pub struct PtrMut { /* private fields */ }Expand description
A type-erased mutable pointer (wide pointer) holding a data pointer and metadata.
This is the base pointer type that can do everything. Uses TaggedPtr for the data pointer, which uses the low bit to distinguish wide vs thin pointers.
No lifetime parameter - safety is the caller’s responsibility.
Implementations§
Source§impl PtrMut
impl PtrMut
Sourcepub fn new<T: ?Sized>(ptr: *mut T) -> Self
pub fn new<T: ?Sized>(ptr: *mut T) -> Self
Creates a new mutable pointer from a raw pointer to a (potentially unsized) object.
Sourcepub const fn new_sized<T: Sized>(ptr: *mut T) -> Self
pub const fn new_sized<T: Sized>(ptr: *mut T) -> Self
Creates a new mutable pointer from a raw pointer to a sized type. This is const because sized types use thin pointers.
Sourcepub unsafe fn with_offset(self, offset: usize) -> Self
pub unsafe fn with_offset(self, offset: usize) -> Self
Creates a new pointer with an offset added to the data pointer. Preserves the wide/thin tag and metadata.
§Safety
Offset must be within bounds of the allocated memory.
Sourcepub fn as_byte_ptr(self) -> *const u8
pub fn as_byte_ptr(self) -> *const u8
Returns the underlying raw pointer as a const byte pointer.
§Panics
Panics if this is a wide pointer.
Sourcepub fn as_mut_byte_ptr(self) -> *mut u8
pub fn as_mut_byte_ptr(self) -> *mut u8
Returns the underlying raw pointer as a mutable byte pointer.
§Panics
Panics if this is a wide pointer.
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
- No mutable references may exist
- The returned reference must not outlive the actual data
Sourcepub unsafe fn as_mut<'a, T: ?Sized>(self) -> &'a mut T
pub unsafe fn as_mut<'a, T: ?Sized>(self) -> &'a mut T
Borrows the underlying object as a mutable reference of type T.
§Safety
Tmust be the actual underlying type- The memory must be valid and initialized
- Caller must have exclusive access
- 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 as_mut_ptr<T: ?Sized>(self) -> *mut T
pub unsafe fn as_mut_ptr<T: ?Sized>(self) -> *mut T
Gets the underlying raw pointer as a mutable 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
Sourcepub unsafe fn drop_in_place<T: ?Sized>(self) -> PtrUninit
pub unsafe fn drop_in_place<T: ?Sized>(self) -> PtrUninit
Drops the value in place and returns a PtrUninit.
§Safety
Tmust be the actual underlying type- The memory must be properly initialized