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>(ptr: *mut T) -> PtrMutwhere
T: ?Sized,
pub fn new<T>(ptr: *mut T) -> PtrMutwhere
T: ?Sized,
Creates a new mutable pointer from a raw pointer to a (potentially unsized) object.
Sourcepub const fn new_sized<T>(ptr: *mut T) -> PtrMut
pub const fn new_sized<T>(ptr: *mut T) -> PtrMut
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) -> PtrMut
pub unsafe fn with_offset(self, offset: usize) -> PtrMut
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>(self) -> &'a Twhere
T: ?Sized,
pub unsafe fn get<'a, T>(self) -> &'a Twhere
T: ?Sized,
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>(self) -> &'a mut Twhere
T: ?Sized,
pub unsafe fn as_mut<'a, T>(self) -> &'a mut Twhere
T: ?Sized,
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>(self) -> *const Twhere
T: ?Sized,
pub unsafe fn as_ptr<T>(self) -> *const Twhere
T: ?Sized,
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>(self) -> *mut Twhere
T: ?Sized,
pub unsafe fn as_mut_ptr<T>(self) -> *mut Twhere
T: ?Sized,
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>(self) -> PtrUninitwhere
T: ?Sized,
pub unsafe fn drop_in_place<T>(self) -> PtrUninitwhere
T: ?Sized,
Drops the value in place and returns a PtrUninit.
§Safety
Tmust be the actual underlying type- The memory must be properly initialized