pub struct WeakMember<T: GarbageCollected> { /* private fields */ }Expand description
WeakMember is similar to Member in that it is used to point to other garbage collected objects. However instead of creating a strong pointer to the object, the WeakMember creates a weak pointer, which does not keep the pointee alive. Hence if all pointers to to a heap allocated object are weak the object will be garbage collected. At the time of GC the weak pointers will automatically be set to null.
Implementations§
Source§impl<T: GarbageCollected> WeakMember<T>
impl<T: GarbageCollected> WeakMember<T>
Sourcepub fn new(other: &impl GetRustObj<T>) -> Self
pub fn new(other: &impl GetRustObj<T>) -> Self
Create a new WeakMember and initialize it with an object.
Sourcepub fn set(&mut self, other: &impl GetRustObj<T>)
pub fn set(&mut self, other: &impl GetRustObj<T>)
Set the object pointed to by this WeakMember .
Sourcepub unsafe fn get(&self) -> Option<&T>
pub unsafe fn get(&self) -> Option<&T>
Get the object pointed to by this
WeakMember
, returning None if the pointer is empty or has been garbage-collected.
§Safety
The caller must ensure that this pointer is being traced correctly by appearing in the trace
implementation of the object that owns the pointer. Between initializing the pointer and calling get(), the pointer must be reachable by the garbage collector.