pub struct PtrConst { /* private fields */ }Expand description
A type-erased read-only pointer.
Wraps PtrMut but only exposes read methods. No lifetime parameter.
Implementations§
Source§impl PtrConst
impl PtrConst
Sourcepub const fn new_sized<T: Sized>(ptr: *const T) -> Self
pub const fn new_sized<T: Sized>(ptr: *const T) -> Self
Creates a new const pointer from a raw pointer to a sized type. This is const because sized types use thin pointers.
Sourcepub fn new_wide(data: *const u8, metadata: *const ()) -> Self
pub fn new_wide(data: *const u8, metadata: *const ()) -> Self
Create a wide pointer from raw data pointer and metadata.
Sourcepub fn as_byte_ptr(self) -> *const u8
pub fn as_byte_ptr(self) -> *const u8
Sourcepub unsafe fn get<'a, T: ?Sized>(self) -> &'a T
pub unsafe fn get<'a, T: ?Sized>(self) -> &'a T
Borrows the underlying object as a reference of type T.
§Safety
Tmust be the actual underlying type- The memory must be valid and initialized
- The returned reference must not outlive the actual data
Sourcepub unsafe fn as_ptr<T: ?Sized>(self) -> *const T
pub unsafe fn as_ptr<T: ?Sized>(self) -> *const T
Gets the underlying raw pointer as a const pointer of type T.
§Safety
Must be called with the original type T.
Sourcepub unsafe fn read<T>(self) -> T
pub unsafe fn read<T>(self) -> T
Reads the value from the pointer.
§Safety
Tmust be the actual underlying type- The memory must be properly initialized
Trait Implementations§
impl Copy for PtrConst
impl Eq for PtrConst
impl StructuralPartialEq for PtrConst
Auto Trait Implementations§
impl Freeze for PtrConst
impl RefUnwindSafe for PtrConst
impl !Send for PtrConst
impl !Sync for PtrConst
impl Unpin for PtrConst
impl UnwindSafe for PtrConst
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more