Skip to main content

TaggedOffsetPtr

Struct TaggedOffsetPtr 

Source
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>

Source

pub const NIL: Self

All-ones bit pattern serving as a NIL sentinel.

Source

pub const fn max_tag() -> u32

Maximum tag value: (1 << TAG_BITS) - 1. Returns 0 when TAG_BITS == 0.

Source

pub const fn max_index() -> u32

Maximum index value: (1 << (32 - TAG_BITS)) - 1. Returns u32::MAX when TAG_BITS == 0.

Source

pub const fn index_mask() -> u32

Bit mask covering the index portion of the packed word.

Source

pub const fn tag_shift() -> u32

Bit shift for the tag (== 32 - TAG_BITS).

Source

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.

Source

pub fn try_new(index: u32, tag: u32) -> Result<Self, TaggedPtrError>

Fallible construction. Returns Err(TagOutOfRange) or Err(IndexOutOfRange) instead of panicking.

Source

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.

Source

pub const fn raw(self) -> u32

Extract the raw packed u32. Useful for serialisation.

Source

pub fn index(self) -> u32

Extract the index portion.

Source

pub fn tag(self) -> u32

Extract the tag portion.

Source

pub fn with_tag(self, new_tag: u32) -> Self

Return a new pointer with the same index but a different tag.

Source

pub fn with_index(self, new_index: u32) -> Self

Return a new pointer with the same tag but a different index.

Source

pub fn is_nil(self) -> bool

True when the pointer is the NIL sentinel.

Trait Implementations§

Source§

impl<T, const TAG_BITS: u32> Clone for TaggedOffsetPtr<T, TAG_BITS>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, const TAG_BITS: u32> Copy for TaggedOffsetPtr<T, TAG_BITS>

Source§

impl<T: Debug, const TAG_BITS: u32> Debug for TaggedOffsetPtr<T, TAG_BITS>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, const TAG_BITS: u32> Eq for TaggedOffsetPtr<T, TAG_BITS>

Source§

impl<T, const TAG_BITS: u32> Hash for TaggedOffsetPtr<T, TAG_BITS>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T, const TAG_BITS: u32> PartialEq for TaggedOffsetPtr<T, TAG_BITS>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl<T, const TAG_BITS: u32> Freeze for TaggedOffsetPtr<T, TAG_BITS>
where PhantomData<T>: Freeze,

§

impl<T, const TAG_BITS: u32> RefUnwindSafe for TaggedOffsetPtr<T, TAG_BITS>

§

impl<T, const TAG_BITS: u32> Send for TaggedOffsetPtr<T, TAG_BITS>
where PhantomData<T>: Send,

§

impl<T, const TAG_BITS: u32> Sync for TaggedOffsetPtr<T, TAG_BITS>
where PhantomData<T>: Sync,

§

impl<T, const TAG_BITS: u32> Unpin for TaggedOffsetPtr<T, TAG_BITS>
where PhantomData<T>: Unpin,

§

impl<T, const TAG_BITS: u32> UnsafeUnpin for TaggedOffsetPtr<T, TAG_BITS>

§

impl<T, const TAG_BITS: u32> UnwindSafe for TaggedOffsetPtr<T, TAG_BITS>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.