#[repr(C, align(8))]pub struct TypeErased<const C: usize> { /* private fields */ }Expand description
Type-erased data on the stack
See the crate-level docs for more info
Implementations§
Source§impl<const C: usize> TypeErased<C>
impl<const C: usize> TypeErased<C>
Sourcepub fn new<T: 'static>(value: T) -> Self
pub fn new<T: 'static>(value: T) -> Self
Creates a new TypeErased by erasing the type of value
§Panics
Panics if size_of::<T>() is greater than C or align_of::<T>() is greater than 8
(eventually these will become compile-time restrictions)
Sourcepub const fn empty() -> Self
pub const fn empty() -> Self
Creates a new TypeErased containing no value
This is effectively equivalent to TypeErased::new::<()>(())
Sourcepub unsafe fn new_unchecked<T>(value: T) -> Self
pub unsafe fn new_unchecked<T>(value: T) -> Self
Creates a new TypeErased by erasing the type of value
§Safety
size_of::<T>() must be less than or equal to C and align_of::<T>() must be less than
or equal to 8.
This function will be deprecated once it is possible to ensure these at compile-time.
Sourcepub const fn as_ptr<T>(&self) -> *const T
pub const fn as_ptr<T>(&self) -> *const T
Gets a pointer to some type T contained in this TypeErased
§Dereferencability
The returned pointer is valid to dereference if:
- The size of
Tis less than or equal toC - The alignment of
Tis less than or equal to 8 - The data in this
TypeErasedis a valid instance ofT(expired references are not valid)
Sourcepub fn as_mut_ptr<T>(&mut self) -> *mut T
pub fn as_mut_ptr<T>(&mut self) -> *mut T
Gets a mutable pointer to some type T contained in this TypeErased
§Dereferencability
The returned pointer is valid to dereference if:
- The size of
Tis less than or equal toC - The alignment of
Tis less than or equal to 8 - The data in this
TypeErasedis a valid instance ofT(expired references are not valid)
Sourcepub unsafe fn assume_type_ref<T>(&self) -> &T
pub unsafe fn assume_type_ref<T>(&self) -> &T
Assumes this TypeErased contains a valid T and returns a reference to it
§Safety
size_of::<T>() must be less than or equal to C, align_of::<T>() must be less than
or equal to 8, and this must contain a valid instance of T (expired references are not valid).
Sourcepub unsafe fn assume_type_mut<T>(&mut self) -> &mut T
pub unsafe fn assume_type_mut<T>(&mut self) -> &mut T
Assumes this TypeErased contains a valid T and returns a mutable reference to it
§Safety
size_of::<T>() must be less than or equal to C, align_of::<T>() must be less than
or equal to 8, and this must contain a valid instance of T (expired references are not valid).
Sourcepub unsafe fn assume_type_take<T>(self) -> T
pub unsafe fn assume_type_take<T>(self) -> T
Assumes this TypeErased contains a valid T and takes ownership of it
§Safety
size_of::<T>() must be less than or equal to C, align_of::<T>() must be less than
or equal to 8, and this must contain a valid instance of T (expired references are not valid).
Sourcepub const fn raw(&self) -> &[MaybeUninit<u8>; C]
pub const fn raw(&self) -> &[MaybeUninit<u8>; C]
Gets the buffer of raw bytes inside
Sourcepub fn raw_mut(&mut self) -> &mut [MaybeUninit<u8>; C]
pub fn raw_mut(&mut self) -> &mut [MaybeUninit<u8>; C]
Gets a mutable reference to the buffer of raw bytes inside