pub struct PointerValuePair<T> { /* private fields */ }
Expand description
A pair consisting of a raw pointer (*const T
) and an integer value, packed so that it takes the size of a pointer.
It is implemented by packing the integer value in the low bits of the pointer that are known to be zero because of alignment constraints.
The size of the value that can be stored alongside the pointer is 3 bits for most types, but ultimately depends on the minimum alignment of T
:
for example, if mem::align_of::<T>() == 16
then 4 bits are available to store the value.
§Notes
Pointers to zero-sized types do not have enough space to store any value, so it must be zero.
Implementations§
Source§impl<T> PointerValuePair<T>
impl<T> PointerValuePair<T>
Sourcepub fn new(ptr: *const T, value: usize) -> PointerValuePair<T>
pub fn new(ptr: *const T, value: usize) -> PointerValuePair<T>
Creates a new PointerValuePair
from the given raw pointer and extra bits.
§Panics
Panics if the pointer type *const T
does not have enough available low bits to store
the value.
Sourcepub const fn available_bits() -> u32
pub const fn available_bits() -> u32
Returns the number of bits available to store the value.