Weak
class Weak<T> Import
Source: use gc::{Weak}; compiler/src/builtin_docs/gc.hy A handle that refers to a value without keeping it alive, made by weak.
upgrade returns the value while something else still keeps it alive,
and None once a collection has freed it. Use it for registries and
caches that must not extend lifetimes. A Weak cannot be sent to
another thread.
Examples#
use gc::{weak, upgrade, Weak};
use tests::assert;
let data = Vec::from([1, 2]);
let w: Weak<Vec<int>> = weak(data);
let alive = match upgrade(w) {
Option::Some(v) => v.len() == 2,
Option::None => false,
};
assert!(alive && data.len() == 2);
See also#
gc::weakgc::upgradeRoot: A strong pin that keeps a value alive, made byroot.