pub struct Ptr<T> { /* private fields */ }Expand description
A transparent wrapper around Option<NonNull<T>> returned by AtomicTaggedPtr operations.
It provides convenient helper methods to convert into raw const/mutable pointers,
access the underlying Option<NonNull<T>>, and supports direct comparisons.
Implementations§
Source§impl<T> Ptr<T>
impl<T> Ptr<T>
Sourcepub const fn new(ptr: Option<NonNull<T>>) -> Self
pub const fn new(ptr: Option<NonNull<T>>) -> Self
Creates a new Ptr wrapper from an Option<NonNull<T>>.
Sourcepub fn as_mut_ptr(self) -> *mut T
pub fn as_mut_ptr(self) -> *mut T
Converts the pointer into a raw mutable pointer *mut T.
Returns a null pointer if the underlying value is None.
Sourcepub fn as_ptr(self) -> *const T
pub fn as_ptr(self) -> *const T
Converts the pointer into a raw const pointer *const T.
Returns a null pointer if the underlying value is None.
Sourcepub unsafe fn as_ref<'a>(self) -> Option<&'a T>
pub unsafe fn as_ref<'a>(self) -> Option<&'a T>
Returns a shared reference to the value if the pointer is not null.
§Safety
The caller must ensure that the pointer is valid, aligned, points to a valid initialized value, and respects the aliasing rules of Rust references.
Sourcepub unsafe fn as_mut<'a>(self) -> Option<&'a mut T>
pub unsafe fn as_mut<'a>(self) -> Option<&'a mut T>
Returns a mutable reference to the value if the pointer is not null.
§Safety
The caller must ensure that the pointer is valid, aligned, points to a valid initialized value, and respects the aliasing rules of Rust references.
Sourcepub fn expect(self, msg: &str) -> NonNull<T>
pub fn expect(self, msg: &str) -> NonNull<T>
Unwraps the inner NonNull<T>, panicking with the given message if it is None.
Sourcepub fn unwrap_or(self, default: NonNull<T>) -> NonNull<T>
pub fn unwrap_or(self, default: NonNull<T>) -> NonNull<T>
Returns the contained NonNull<T> or a default.
Sourcepub fn map<U, F>(self, f: F) -> Ptr<U>
pub fn map<U, F>(self, f: F) -> Ptr<U>
Maps the inner NonNull<T> pointer to a new pointer of another type.
Sourcepub fn map_or<U, F>(self, default: U, f: F) -> U
pub fn map_or<U, F>(self, default: U, f: F) -> U
Maps the inner NonNull<T> pointer to a value, or returns a default value.
Sourcepub fn map_or_else<U, D, F>(self, default: D, f: F) -> U
pub fn map_or_else<U, D, F>(self, default: D, f: F) -> U
Maps the inner NonNull<T> pointer to a value, or evaluates a default closure.