pub struct Opaque<'mem>(/* private fields */);Expand description
A type-erased pointer to an initialized value
Implementations§
Source§impl<'mem> Opaque<'mem>
impl<'mem> Opaque<'mem>
Sourcepub fn from_ref<T>(r: &'mem mut T) -> Opaque<'mem>
pub fn from_ref<T>(r: &'mem mut T) -> Opaque<'mem>
Create a new opaque pointer from a mutable reference
Sourcepub unsafe fn new_unchecked<T>(ptr: *mut T) -> Opaque<'mem>
pub unsafe fn new_unchecked<T>(ptr: *mut T) -> Opaque<'mem>
Create a new opaque pointer from a raw pointer
§Safety
The pointer must be valid, aligned, and point to initialized memory
of the correct type, and be valid for lifetime 'mem.
Sourcepub fn as_byte_ptr(self) -> *const u8
pub fn as_byte_ptr(self) -> *const u8
Gets the underlying raw pointer
Sourcepub fn as_mut_byte_ptr(self) -> *mut u8
pub fn as_mut_byte_ptr(self) -> *mut u8
Gets the underlying raw pointer as mutable
Sourcepub unsafe fn as_ptr<T>(self) -> *const T
pub unsafe fn as_ptr<T>(self) -> *const T
Gets the underlying raw pointer as a pointer of type T
§Safety
Must be called with the original type T that was used to create this pointer
Sourcepub unsafe fn as_mut<'borrow, T>(self) -> &'borrow mut Twhere
'borrow: 'mem,
pub unsafe fn as_mut<'borrow, T>(self) -> &'borrow mut Twhere
'borrow: 'mem,
Gets the underlying raw pointer as a mutable pointer of type T
§Safety
T must be the actual iunderlying type. You’re downcasting with no guardrails.
Sourcepub unsafe fn as_ref<'borrow, T>(self) -> &'borrow Twhere
'borrow: 'mem,
pub unsafe fn as_ref<'borrow, T>(self) -> &'borrow Twhere
'borrow: 'mem,
Gets the underlying raw pointer as a const pointer of type T
§Safety
T must be the actual underlying type. You’re downcasting with no guardrails.
Sourcepub fn as_const<'borrow>(self) -> OpaqueConst<'borrow>where
'borrow: 'mem,
pub fn as_const<'borrow>(self) -> OpaqueConst<'borrow>where
'borrow: 'mem,
Make a const ptr out of this mut ptr
Sourcepub unsafe fn read<T>(self) -> T
pub unsafe fn read<T>(self) -> T
Exposes std::ptr::read
§Safety
T must be the actual underlying type of the pointed-to memory.
The memory must be properly initialized and aligned for type T.
Sourcepub unsafe fn drop_in_place<T>(self)
pub unsafe fn drop_in_place<T>(self)
Exposes std::ptr::drop_in_place
§Safety
T must be the actual underlying type of the pointed-to memory.
The memory must be properly initialized and aligned for type T.
After calling this function, the memory should not be accessed again
until it is properly reinitialized.