Skip to main content

DynamicManagedGc

Struct DynamicManagedGc 

Source
pub struct DynamicManagedGc { /* private fields */ }
Expand description

Type-erased garbage collected box.

The ManagedGc counterpart for script values. See the module docs for the ownership model.

Implementations§

Source§

impl DynamicManagedGc

Source

pub fn new<T: Finalize>(data: T) -> Self

Allocates a value and owns it.

Source

pub unsafe fn new_cyclic<T: Finalize>(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 new_raw( type_hash: TypeHash, lifetime: Lifetime, memory: *mut u8, layout: Layout, finalizer: impl Into<Finalizer>, ) -> Self

Takes ownership of an existing allocation.

The box will free memory and run finalizer when it is dropped.

§Panics

Panics when memory is null.

Source

pub fn new_uninitialized( type_hash: TypeHash, layout: Layout, finalizer: impl Into<Finalizer>, ) -> Self

Allocates room for a value without writing one into it.

The finalizer still runs on drop, so the caller must fill the memory before the box is dropped or read.

Source

pub fn reference(&self) -> Self

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

Source

pub fn consume<T>(self) -> Result<T, Self>

Takes the value out and frees the allocation.

Gives the box back when it does not own the value, the type does not match, or something is accessing it.

Source

pub fn into_typed<T>(self) -> ManagedGc<T>

Puts a type back on the box.

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 layout(&self) -> &Layout

Returns the layout of the allocation.

Source

pub fn finalizer(&self) -> &Finalizer

Returns the drop function of the stored type.

Source

pub unsafe fn memory(&self) -> &[u8]

Returns the value as raw bytes.

§Safety

Bypasses the borrow state, and does not check that the value is still alive.

Source

pub unsafe fn memory_mut(&mut self) -> &mut [u8]

Returns the value as mutable raw bytes.

§Safety

Bypasses the borrow state, does not check that the value is still alive, and writing bytes that are not a valid value of the stored type makes every later access undefined.

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 is<T>(&self) -> bool

Returns true when the value is a T.

Source

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

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

§Panics

Panics when the value is not a T.

Source

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

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

§Panics

Panics when the value is not a T.

Source

pub fn read<const LOCKING: bool, T>(&self) -> ValueReadAccess<'_, T>

Guards the value for reading, spinning until it is free when LOCKING.

§Panics

Panics when the value is not a T, is gone, or is busy and LOCKING is false.

Source

pub fn write<const LOCKING: bool, T>(&mut self) -> ValueWriteAccess<'_, T>

Guards the value for writing, spinning until it is free when LOCKING.

§Panics

Panics when the value is not a T, is gone, or is busy and LOCKING is false.

Source

pub fn try_borrow(&self) -> Option<DynamicManagedRef>

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

Source

pub fn try_borrow_mut(&self) -> Option<DynamicManagedRefMut>

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

Source

pub fn borrow<const LOCKING: bool>(&self) -> DynamicManagedRef

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) -> DynamicManagedRefMut

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) -> DynamicManagedLazy

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

§Panics

Panics when the value is gone.

Source

pub unsafe fn as_ptr_raw(&self) -> *const u8

Returns the allocation pointer, checking nothing.

§Safety

Neither the type, the borrow state, nor whether the value is still alive is checked.

Source

pub unsafe fn as_mut_ptr_raw(&mut self) -> *mut u8

Returns the mutable allocation pointer, checking nothing.

§Safety

Neither the type, the borrow state, nor whether the value is still alive is checked.

Trait Implementations§

Source§

impl Drop for DynamicManagedGc

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl From<DynamicManagedGc> for DynamicManagedValue

Source§

fn from(value: DynamicManagedGc) -> Self

Converts to this type from the input type.
Source§

impl Send for DynamicManagedGc

Source§

impl Sync for DynamicManagedGc

Source§

impl TryFrom<DynamicManagedValue> for DynamicManagedGc

Source§

type Error = ()

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

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

Performs the conversion.

Auto Trait Implementations§

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, 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.