Skip to main content

ManagedGc

Struct ManagedGc 

Source
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>

Source

pub fn new(data: T) -> Self

Allocates a value and owns it.

Source

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.

Source

pub fn reference(&self) -> Self

Takes another handle that references the same value without owning it.

Source

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.

Source

pub fn into_dynamic(self) -> DynamicManagedGc

Erases the type.

Source

pub fn renew(&mut self)

Replaces the lifetime, killing every reference taken so far. Does nothing on a referencing handle.

Source

pub fn type_hash(&self) -> TypeHash

Returns the type of the value.

Source

pub fn lifetime(&self) -> ManagedGcLifetime<'_>

Returns the borrow state, and with it whether this handle owns the value.

Source

pub fn exists(&self) -> bool

Returns true while the value is alive.

Always true for the owner.

Source

pub fn is_owning(&self) -> bool

Returns true when this handle owns the value.

Source

pub fn is_referencing(&self) -> bool

Returns true when this handle only references the value.

Source

pub fn is_owned_by(&self, other: &Self) -> bool

Returns true when this handle references the value that other owns.

Source

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.

Source

pub fn try_read(&self) -> Option<ValueReadAccess<'_, T>>

Guards the value for reading, or returns None when it is busy or gone.

Source

pub fn try_write(&mut self) -> Option<ValueWriteAccess<'_, T>>

Guards the value for writing, or returns None when it is busy or gone.

Source

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.

Source

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.

Source

pub fn try_borrow(&self) -> Option<ManagedRef<T>>

Takes a shared handle, or returns None when the value is busy or gone.

Source

pub fn try_borrow_mut(&self) -> Option<ManagedRefMut<T>>

Takes an exclusive handle, or returns None when the value is busy or gone.

Source

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.

Source

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.

Source

pub fn lazy(&self) -> ManagedLazy<T>

Takes an unclaimed handle, which claims nothing and never blocks.

§Panics

Panics when the value is gone.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<T: Default> Default for ManagedGc<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> From<ManagedGc<T>> for ManagedValue<T>

Source§

fn from(value: ManagedGc<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> Send for ManagedGc<T>

Source§

impl<T> Sync for ManagedGc<T>

Source§

impl<T> TryFrom<ManagedValue<T>> for ManagedGc<T>

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(value: ManagedValue<T>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for ManagedGc<T>

§

impl<T> !UnwindSafe for ManagedGc<T>

§

impl<T> Freeze for ManagedGc<T>
where PhantomData<fn() -> T>: Freeze,

§

impl<T> Unpin for ManagedGc<T>
where PhantomData<fn() -> T>: Unpin,

§

impl<T> UnsafeUnpin for ManagedGc<T>
where PhantomData<fn() -> T>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Finalize for T

Source§

unsafe fn finalize_raw(data: *mut ())

Drops the value stored at data in place. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Initialize for T
where T: Default,

Source§

fn initialize() -> T

Returns the initial value of this type.
Source§

unsafe fn initialize_raw(data: *mut ())

Writes the initial value into already allocated memory. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.