pub struct PackedPointer<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool = true> { /* private fields */ }Expand description
A pointer wrapper that allows storing a small amount of data in the alignment bits of the pointer.
The number of bits available for packing (DATA_BITS) must be less than or equal to the number
of trailing zero bits in the alignment of T.
PackedPointer enforces compile-time validation of the alignment constraints using const
assertions, and runtime debug assertions to verify pointer alignment and data limits.
If CHECK_ALIGNMENT is set to false, the compile-time alignment check is bypassed. This can
be useful when working with types whose alignment cannot be validated at compile-time.
This implementation preserves pointer provenance by using Rust’s strict provenance methods
(addr, with_addr, map_addr).
Implementations§
Source§impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
Sourcepub fn new(ptr: *mut T, data: usize) -> Self
pub fn new(ptr: *mut T, data: usize) -> Self
Creates a new PackedPointer from a pointer and data.
§Panics
Panics in debug builds if the pointer is not aligned to the required boundary, or if the data exceeds the allowed number of bits.
Sourcepub fn from_ptr(ptr: *mut T) -> Self
pub fn from_ptr(ptr: *mut T) -> Self
Creates a PackedPointer from a pointer with zeroed data bits.
Sourcepub const fn from_data(data: usize) -> Self
pub const fn from_data(data: usize) -> Self
Creates a PackedPointer with a null pointer and specified data.
§Panics
Panics if the data exceeds the allowed number of bits.
Trait Implementations§
Source§impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> Clone for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> Clone for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
Source§impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> Debug for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> Debug for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
Source§impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> Default for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> Default for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
Source§impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> From<*mut T> for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> From<*mut T> for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
Source§impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> PartialEq<*const T> for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> PartialEq<*const T> for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
Source§impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> PartialEq<*mut T> for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> PartialEq<*mut T> for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
Source§impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> PartialEq for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> PartialEq for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> Copy for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> Eq for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
Auto Trait Implementations§
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> Freeze for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> RefUnwindSafe for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>where
T: RefUnwindSafe,
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool = true> !Send for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool = true> !Sync for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> Unpin for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> UnsafeUnpin for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>
impl<T, const DATA_BITS: usize, const CHECK_ALIGNMENT: bool> UnwindSafe for PackedPointer<T, DATA_BITS, CHECK_ALIGNMENT>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
slot. Read more