pub struct ManagedGc<T> { /* private fields */ }Expand description
Typed garbage collected box.
See the module docs for the ownership model.
Implementations§
Source§impl<T> ManagedGc<T>
impl<T> ManagedGc<T>
Sourcepub unsafe fn new_cyclic(f: impl FnOnce(Self) -> T) -> Self
pub unsafe fn new_cyclic(f: impl FnOnce(Self) -> T) -> Self
Allocates a value that can point back at itself.
f is handed a reference to the box before the value exists, so it can
store it inside the value it returns.
§Safety
The handle passed to f points at memory that is not written yet.
Storing it is fine, but reading or writing through it before f
returns is undefined.
Sourcepub fn reference(&self) -> Self
pub fn reference(&self) -> Self
Takes another handle that references the same value without owning it.
Sourcepub fn consume(self) -> Result<T, Self>
pub fn consume(self) -> Result<T, Self>
Takes the value out and frees the allocation.
Gives the box back when it does not own the value or something is accessing it.
Sourcepub fn into_dynamic(self) -> DynamicManagedGc
pub fn into_dynamic(self) -> DynamicManagedGc
Erases the type.
Sourcepub fn renew(&mut self)
pub fn renew(&mut self)
Replaces the lifetime, killing every reference taken so far. Does nothing on a referencing handle.
Sourcepub fn lifetime(&self) -> ManagedGcLifetime<'_>
pub fn lifetime(&self) -> ManagedGcLifetime<'_>
Returns the borrow state, and with it whether this handle owns the value.
Sourcepub fn is_referencing(&self) -> bool
pub fn is_referencing(&self) -> bool
Returns true when this handle only references the value.
Sourcepub fn is_owned_by(&self, other: &Self) -> bool
pub fn is_owned_by(&self, other: &Self) -> bool
Returns true when this handle references the value that other owns.
Sourcepub fn transfer_ownership(&mut self, new_owner: &mut Self) -> bool
pub fn transfer_ownership(&mut self, new_owner: &mut Self) -> bool
Hands ownership over to a handle that references this value.
Returns false unless this handle owns the value and new_owner
references it.
Sourcepub fn try_read(&self) -> Option<ValueReadAccess<'_, T>>
pub fn try_read(&self) -> Option<ValueReadAccess<'_, T>>
Guards the value for reading, or returns None when it is busy or
gone.
Sourcepub fn try_write(&mut self) -> Option<ValueWriteAccess<'_, T>>
pub fn try_write(&mut self) -> Option<ValueWriteAccess<'_, T>>
Guards the value for writing, or returns None when it is busy or
gone.
Sourcepub fn read<const LOCKING: bool>(&self) -> ValueReadAccess<'_, T>
pub fn read<const LOCKING: bool>(&self) -> ValueReadAccess<'_, T>
Guards the value for reading, spinning until it is free when LOCKING.
§Panics
Panics when the value is gone, or when it is busy and LOCKING is
false.
Sourcepub fn write<const LOCKING: bool>(&mut self) -> ValueWriteAccess<'_, T>
pub fn write<const LOCKING: bool>(&mut self) -> ValueWriteAccess<'_, T>
Guards the value for writing, spinning until it is free when LOCKING.
§Panics
Panics when the value is gone, or when it is busy and LOCKING is
false.
Sourcepub fn try_borrow(&self) -> Option<ManagedRef<T>>
pub fn try_borrow(&self) -> Option<ManagedRef<T>>
Takes a shared handle, or returns None when the value is busy or
gone.
Sourcepub fn try_borrow_mut(&self) -> Option<ManagedRefMut<T>>
pub fn try_borrow_mut(&self) -> Option<ManagedRefMut<T>>
Takes an exclusive handle, or returns None when the value is busy or
gone.
Sourcepub fn borrow<const LOCKING: bool>(&self) -> ManagedRef<T>
pub fn borrow<const LOCKING: bool>(&self) -> ManagedRef<T>
Takes a shared handle, spinning until it is free when LOCKING.
§Panics
Panics when the value is gone, or when it is busy and LOCKING is
false.
Sourcepub fn borrow_mut<const LOCKING: bool>(&mut self) -> ManagedRefMut<T>
pub fn borrow_mut<const LOCKING: bool>(&mut self) -> ManagedRefMut<T>
Takes an exclusive handle, spinning until it is free when LOCKING.
§Panics
Panics when the value is gone, or when it is busy and LOCKING is
false.
Sourcepub fn lazy(&self) -> ManagedLazy<T>
pub fn lazy(&self) -> ManagedLazy<T>
Takes an unclaimed handle, which claims nothing and never blocks.
§Panics
Panics when the value is gone.
Sourcepub unsafe fn as_ptr(&self) -> *const T
pub unsafe fn as_ptr(&self) -> *const T
Returns a pointer to the value, checking nothing.
§Safety
Neither the borrow state nor whether the value is still alive is checked.
Sourcepub unsafe fn as_mut_ptr(&mut self) -> *mut T
pub unsafe fn as_mut_ptr(&mut self) -> *mut T
Returns a mutable pointer to the value, checking nothing.
§Safety
Neither the borrow state nor whether the value is still alive is checked.