pub struct TaggedPointer { /* private fields */ }Expand description
A pointer that holds a data pointer plus additional data stored as a Discriminant
Note: The discriminant must be <= MAX_DISCRIMINANT, which is feature-dependent
Implementations§
Source§impl TaggedPointer
impl TaggedPointer
Sourcepub fn new(ptr: usize, discriminant: Discriminant) -> Self
pub fn new(ptr: usize, discriminant: Discriminant) -> Self
Create a new tagged pointer from a pointer and a discriminant
§Panics
Panics if discriminant is greater than MAX_DISCRIMINANT or if
ptr is greater than MAX_POINTER_VALUE
Sourcepub unsafe fn new_unchecked(ptr: usize, discriminant: Discriminant) -> Self
pub unsafe fn new_unchecked(ptr: usize, discriminant: Discriminant) -> Self
Create a new tagged pointer from a pointer and a discriminant without checking invariance
§Safety
discriminant must be <= MAX_DISCRIMINANT and pointer must be <=
MAX_POINTER_VALUE
Sourcepub const fn discriminant(self) -> Discriminant
pub const fn discriminant(self) -> Discriminant
Fetches the discriminant of the tagged pointer
Sourcepub unsafe fn as_ref<T>(&self) -> &T
pub unsafe fn as_ref<T>(&self) -> &T
Gains a reference to the inner value of the pointer
§Safety
The pointer given to TaggedPointer::new must be properly aligned and non-null
Sourcepub unsafe fn as_mut_ref<T>(&mut self) -> &mut T
pub unsafe fn as_mut_ref<T>(&mut self) -> &mut T
Gains a mutable reference to the inner value of the pointer
§Safety
The pointer given to TaggedPointer::new must be properly aligned and non-null
Sourcepub const fn as_raw_usize(self) -> usize
pub const fn as_raw_usize(self) -> usize
Returns the raw tagged pointer, without removing the discriminant
§Warning
Attempting to dereference this usize will not point to valid memory!
Sourcepub const fn as_ptr<T>(self) -> *const T
pub const fn as_ptr<T>(self) -> *const T
Converts a tagged pointer into a raw pointer, removing the discriminant
Sourcepub fn as_mut_ptr<T>(self) -> *mut T
pub fn as_mut_ptr<T>(self) -> *mut T
Converts a tagged pointer into a raw pointer, removing the discriminant
Sourcepub fn store_discriminant(pointer: usize, discriminant: Discriminant) -> usize
pub fn store_discriminant(pointer: usize, discriminant: Discriminant) -> usize
Store a Discriminant into a tagged pointer
§Panics
Panics if discriminant is greater than MAX_DISCRIMINANT or if
ptr is greater than MAX_POINTER_VALUE
Sourcepub unsafe fn store_discriminant_unchecked(
pointer: usize,
discriminant: Discriminant,
) -> usize
pub unsafe fn store_discriminant_unchecked( pointer: usize, discriminant: Discriminant, ) -> usize
Store a Discriminant into a tagged pointer without any checks
§Safety
discriminant must be <= MAX_DISCRIMINANT and pointer must be <=
MAX_POINTER_VALUE
Sourcepub const fn fetch_discriminant(pointer: usize) -> Discriminant
pub const fn fetch_discriminant(pointer: usize) -> Discriminant
Fetch a Discriminant from a tagged pointer
Sourcepub const fn strip_discriminant(pointer: usize) -> usize
pub const fn strip_discriminant(pointer: usize) -> usize
Strip the Discriminant from a tagged pointer, returning only the valid pointer as a usize
Trait Implementations§
Source§impl Binary for TaggedPointer
impl Binary for TaggedPointer
Source§impl Clone for TaggedPointer
impl Clone for TaggedPointer
Source§fn clone(&self) -> TaggedPointer
fn clone(&self) -> TaggedPointer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more