pub struct TaggedOffsetPtr<T, const TAG_BITS: u32> { /* private fields */ }Expand description
A 32-bit position-independent pointer with TAG_BITS high bits
reserved for a caller-defined tag. Packs (tag, index) into one
u32. Cross-process safe: same raw bits resolve to the same
(tag, index) in every process.
Implementations§
Source§impl<T, const TAG_BITS: u32> TaggedOffsetPtr<T, TAG_BITS>
impl<T, const TAG_BITS: u32> TaggedOffsetPtr<T, TAG_BITS>
Sourcepub const fn max_tag() -> u32
pub const fn max_tag() -> u32
Maximum tag value: (1 << TAG_BITS) - 1. Returns 0 when
TAG_BITS == 0.
Sourcepub const fn max_index() -> u32
pub const fn max_index() -> u32
Maximum index value: (1 << (32 - TAG_BITS)) - 1. Returns
u32::MAX when TAG_BITS == 0.
Sourcepub const fn index_mask() -> u32
pub const fn index_mask() -> u32
Bit mask covering the index portion of the packed word.
Sourcepub fn new(index: u32, tag: u32) -> Self
pub fn new(index: u32, tag: u32) -> Self
Construct from (index, tag). Panics if either component
exceeds its range. Use try_new for
fallible construction.
Sourcepub fn try_new(index: u32, tag: u32) -> Result<Self, TaggedPtrError>
pub fn try_new(index: u32, tag: u32) -> Result<Self, TaggedPtrError>
Fallible construction. Returns Err(TagOutOfRange) or
Err(IndexOutOfRange) instead of panicking.
Sourcepub const fn from_raw(packed: u32) -> Self
pub const fn from_raw(packed: u32) -> Self
Construct from the raw packed u32 representation. Useful
for deserialisation. Caller is responsible for ensuring the
raw value is meaningful for the chosen TAG_BITS.
Sourcepub fn with_tag(self, new_tag: u32) -> Self
pub fn with_tag(self, new_tag: u32) -> Self
Return a new pointer with the same index but a different tag.
Sourcepub fn with_index(self, new_index: u32) -> Self
pub fn with_index(self, new_index: u32) -> Self
Return a new pointer with the same tag but a different index.