#[repr(transparent)]
pub struct TaggedPtr<T, const BITS: usize>(_);
Expand description

A tagged pointer: a space-efficient representation of a pointer and integer tag.

This type stores a pointer and an integer tag without taking up more space than a normal pointer (unless the fallback implementation is used; see the crate documentation).

The tagged pointer conceptually holds a NonNull<T> and a certain number of bits of an integer tag.

BITS specifies how many bits are used for the tag. The alignment of T must be large enough to store this many bits; see Self::new.

Implementations

Creates a new tagged pointer. Only the lower BITS bits of tag are stored.

Panics

This function panics if the alignment of T is less than 2 to the power of BITS. This ensures that all properly aligned pointers to T will be aligned enough to store the specified number of bits of the tag.

ptr should be “dereferencable” in the sense defined by core::ptr. If it is not, this function or methods of TaggedPtr may panic.

It is recommended that ptr be properly aligned (i.e., aligned to at least mem::align_of::<T>()), but it may have a smaller alignment. However, if its alignment is not at least 2 to the power of BITS, this function may panic.

Gets the pointer and tag stored by the tagged pointer. If you need both the pointer and tag, this method may be more efficient than calling Self::ptr and Self::tag separately.

Panics

If the pointer provided to Self::new wasn’t “dereferencable”, this method may panic.

Gets the pointer stored by the tagged pointer, without the tag. Equivalent to self.get().0.

Panics

If the pointer provided to Self::new wasn’t “dereferencable”, this method may panic.

Gets the tag stored by the tagged pointer. Equivalent to self.get().1.

Panics

If the pointer provided to Self::new wasn’t “dereferencable”, this method may panic.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

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

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.