Skip to main content

weak_key

Function weak_key 

Source
pub fn weak_key(value: &Value) -> Option<WeakKey>
Expand description

Turn a script value into a weak key, if CanBeHeldWeakly allows it.

The rule is “an object, or a symbol that is not in the registry”. A registered symbol — one from Symbol.for — is refused on purpose: it lives in the realm’s registry for the lifetime of the realm, so it never dies, and a weak entry keyed by it could never be observed to be collected. A plain Symbol() is a fresh allocation each time and so has a lifetime worth observing.