Under heavy development. This site describes the intended 1.0 language. Current features and performance vary. Development status
Sn50SnThe SnAPI programming language
0.2.0 Preview 1 · Frozen documentation

Weak

Retains a shared control block while permitting the payload to expire.

Sn is under heavy development. Reference extracted from this release’s bundled standard library. Public API examples are not an exhaustive compatibility test. Read the matching release guide for tested workflows and limitations. Read the status →

Module std.memory

import std.memory;

Public declaration contracts and authored examples. A page can document several related symbols. Implementation bodies are excluded.

Weak

pub final class Weak<T, A = DefaultAllocator>
    where T: Movable where A: Allocator, Defaultable, Movable

Retains a shared control block while permitting the payload to expire.

Copying retains only weak control ownership and never copies T. Upgrade atomically acquires a new strong handle or returns none after expiry; it never resurrects a destroyed payload. Separate published handles support concurrent retention/release, while access to the same mutable handle requires external synchronization. No payload borrow is available directly from Weak. T: Movable payload observed only after a successful strong upgrade. A: Movable Defaultable allocator retained until final control cleanup.

Weak.init

pub init()

Creates an empty weak observer without allocation.

Weak.init

pub init(Source: readonly Self&)

Retains the source control block without retaining its payload. Source: Existing weak observer or empty handle.

Weak.init

pub init(Source: mut Self&&)

Transfers one weak lease without retention. Source: Writable observer left empty.

Weak.operator

pub fn operator =(Source: readonly Self&) -> void

Retains source control before releasing the destination lease. Source: Observer to retain; exact self-assignment is unchanged. Return: No value.

Weak.operator

pub fn operator =(Source: mut Self&&) -> void

Releases old control ownership and transfers Source. Source: Observer left empty; exact self-move is unchanged. Return: No value.

Weak.IsEmpty

pub IsEmpty: bool;

Reports absence of a control lease, independently of payload expiry. Return: True only for empty/moved-from observers.

Weak.Upgrade

pub readonly fn Upgrade() -> Shared<T, A>?

Atomically acquires a strong owner while the payload is still live. Return: New strong owner, or none for an empty/expired observer; no allocation.

Weak.Clear

pub fn Clear() -> void

Releases this weak lease, possibly freeing the final control record. Return: No value; the observer is empty before control cleanup begins.

Documentation snapshot: October 24, 2026 About versions ↗
Searching Development · language & standard library