pub struct DynamicManaged { /* private fields */ }Expand description
Implementations§
Source§impl DynamicManaged
impl DynamicManaged
Sourcepub fn new<T: Finalize>(data: T) -> Result<Self, T>
pub fn new<T: Finalize>(data: T) -> Result<Self, T>
Moves a value into a new allocation, giving it back when the allocation fails.
Sourcepub fn new_raw(
type_hash: TypeHash,
lifetime: Lifetime,
memory: *mut u8,
layout: Layout,
finalizer: impl Into<Finalizer>,
) -> Option<Self>
pub fn new_raw( type_hash: TypeHash, lifetime: Lifetime, memory: *mut u8, layout: Layout, finalizer: impl Into<Finalizer>, ) -> Option<Self>
Takes ownership of an existing allocation.
Returns None for a null pointer. The box will free memory and run
finalizer on drop.
Sourcepub fn new_uninitialized(
type_hash: TypeHash,
layout: Layout,
finalizer: impl Into<Finalizer>,
) -> Self
pub fn new_uninitialized( type_hash: TypeHash, layout: Layout, finalizer: impl Into<Finalizer>, ) -> Self
Allocates room for a value without writing one into it.
Nothing stops the box from running its finalizer on drop, so the caller must fill the memory before it is dropped or read.
Sourcepub unsafe fn from_bytes(
type_hash: TypeHash,
lifetime: Lifetime,
bytes: Vec<u8>,
layout: Layout,
finalizer: impl Into<Finalizer>,
) -> Self
pub unsafe fn from_bytes( type_hash: TypeHash, lifetime: Lifetime, bytes: Vec<u8>, layout: Layout, finalizer: impl Into<Finalizer>, ) -> Self
Builds a box by copying a byte image of a value into a new allocation.
§Safety
bytes must be a valid image of a value of the type named by
type_hash, matching layout, and it is moved, so the caller must not
drop the source afterwards.
Sourcepub fn into_inner(self) -> (TypeHash, Lifetime, *mut u8, Layout, Finalizer)
pub fn into_inner(self) -> (TypeHash, Lifetime, *mut u8, Layout, Finalizer)
Splits into the parts the box was built from, and stops it from freeing the allocation.
The caller becomes responsible for running the finalizer and freeing the memory.
Sourcepub fn into_typed<T>(self) -> Result<Managed<T>, Self>
pub fn into_typed<T>(self) -> Result<Managed<T>, Self>
Moves the value into a typed box, giving self back on a type mismatch
or while it is accessed.
Sourcepub unsafe fn memory(&self) -> &[u8] ⓘ
pub unsafe fn memory(&self) -> &[u8] ⓘ
Returns the value as raw bytes.
§Safety
Bypasses the borrow state, so the caller must know that nothing is writing the value.
Sourcepub unsafe fn memory_mut(&mut self) -> &mut [u8] ⓘ
pub unsafe fn memory_mut(&mut self) -> &mut [u8] ⓘ
Returns the value as mutable raw bytes.
§Safety
Bypasses the borrow state, and writing bytes that are not a valid value of the stored type makes every later access undefined.
Sourcepub fn read<T>(&self) -> Option<ValueReadAccess<'_, T>>
pub fn read<T>(&self) -> Option<ValueReadAccess<'_, T>>
Guards the value for reading, or returns None on a type mismatch or
while it is written.
Sourcepub fn write<T>(&mut self) -> Option<ValueWriteAccess<'_, T>>
pub fn write<T>(&mut self) -> Option<ValueWriteAccess<'_, T>>
Guards the value for writing, or returns None on a type mismatch or
while it is accessed.
Sourcepub fn consume<T>(self) -> Result<T, Self>
pub fn consume<T>(self) -> Result<T, Self>
Takes the value out and frees the allocation.
Gives the box back on a type mismatch or while any access guard is live.
Sourcepub fn move_into_ref(self, target: DynamicManagedRefMut) -> Result<(), Self>
pub fn move_into_ref(self, target: DynamicManagedRefMut) -> Result<(), Self>
Moves the value into the place target points at and frees this
allocation.
Gives the box back when the types differ or both sides are the same allocation.
Sourcepub fn move_into_lazy(self, target: DynamicManagedLazy) -> Result<(), Self>
pub fn move_into_lazy(self, target: DynamicManagedLazy) -> Result<(), Self>
Moves the value into the place target points at and frees this
allocation.
Gives the box back when the types differ or both sides are the same allocation.
Sourcepub fn borrow(&self) -> Option<DynamicManagedRef>
pub fn borrow(&self) -> Option<DynamicManagedRef>
Takes a shared handle, or returns None when an exclusive one is out.
Sourcepub fn borrow_mut(&mut self) -> Option<DynamicManagedRefMut>
pub fn borrow_mut(&mut self) -> Option<DynamicManagedRefMut>
Takes an exclusive handle, or returns None when any handle is out.
Sourcepub fn lazy(&self) -> DynamicManagedLazy
pub fn lazy(&self) -> DynamicManagedLazy
Takes an unclaimed handle.
Sourcepub unsafe fn try_map<T, U: Finalize>(
self,
f: impl FnOnce(T) -> Option<U>,
) -> Option<Self>
pub unsafe fn try_map<T, U: Finalize>( self, f: impl FnOnce(T) -> Option<U>, ) -> Option<Self>
DynamicManaged::map that can decline, dropping the value when it
does.
§Safety
Same as DynamicManaged::map.
Sourcepub unsafe fn as_ptr<T>(&self) -> Option<*const T>
pub unsafe fn as_ptr<T>(&self) -> Option<*const T>
Returns a typed pointer while nothing is accessing the value.
§Safety
The caller takes over checking for conflicting access.
Sourcepub unsafe fn as_mut_ptr<T>(&mut self) -> Option<*mut T>
pub unsafe fn as_mut_ptr<T>(&mut self) -> Option<*mut T>
Returns a typed mutable pointer while nothing is accessing the value.
§Safety
The caller takes over checking for conflicting access.
Sourcepub unsafe fn as_ptr_raw(&self) -> *const u8
pub unsafe fn as_ptr_raw(&self) -> *const u8
Returns the allocation pointer, checking nothing at all.
§Safety
Neither the type nor the borrow state is checked.
Sourcepub unsafe fn as_mut_ptr_raw(&mut self) -> *mut u8
pub unsafe fn as_mut_ptr_raw(&mut self) -> *mut u8
Returns the mutable allocation pointer, checking nothing at all.
§Safety
Neither the type nor the borrow state is checked.