Function in gc compiler

weak

fn weak<T>(T value) -> Weak<T>
Import
use gc::{weak};
Source: compiler/src/builtin_docs/gc.hy

Makes a handle to value that does not keep it alive.

Values that are not heap objects (int, bool, float, …) are never collected, so their Weak always upgrades. value can be of any type: a weak of an Option or a Result refers to the heap object it holds.

Parameters#

NameType
valueT

Returns#

Weak<T>

Examples#

use gc::{weak, upgrade};
use tests::assert;
let w = weak(5);
assert!(match upgrade(w) { Option::Some(n) => n == 5, Option::None => false });

See also#

↑ ↓ navigate ↵ open