pub struct OpaqueConst<'mem>(/* private fields */);Expand description
A type-erased read-only pointer to an initialized value.
Cannot be null. May be dangling (for ZSTs)
Implementations§
Source§impl<'mem> OpaqueConst<'mem>
impl<'mem> OpaqueConst<'mem>
Sourcepub fn from_ref<T>(r: &'mem T) -> OpaqueConst<'mem>
pub fn from_ref<T>(r: &'mem T) -> OpaqueConst<'mem>
Create a new opaque const pointer from a reference
Sourcepub unsafe fn new_unchecked<T>(ptr: *const T) -> OpaqueConst<'mem>
pub unsafe fn new_unchecked<T>(ptr: *const T) -> OpaqueConst<'mem>
Create a new opaque const 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 as a byte pointer
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_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 unsafe fn field(self, offset: usize) -> OpaqueConst<'mem>
pub unsafe fn field(self, offset: usize) -> OpaqueConst<'mem>
Returns a pointer with the given offset added
§Safety
Offset must be within the bounds of the allocated memory, and the resulting pointer must be properly aligned.
Trait Implementations§
Source§impl<'mem> Clone for OpaqueConst<'mem>
impl<'mem> Clone for OpaqueConst<'mem>
Source§fn clone(&self) -> OpaqueConst<'mem>
fn clone(&self) -> OpaqueConst<'mem>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more