Struct TaggedPtr

Source
pub struct TaggedPtr<T>(/* private fields */);
Expand description

A tagged pointer with the maximum tag size for the given type.

This type behaves like crate::TaggedPtr but doesn’t have a BITS parameter that determines how many tag bits to store. Instead, this type uses the largest possible tag size for an aligned pointer to T; see Self::BITS for the exact calculation.

Unlike crate::TaggedPtr, this type always requires pointers to be properly aligned, even if you don’t need all the available tag bits; see Self::new.

Implementations§

Source§

impl<T> TaggedPtr<T>

Source

pub const BITS: u32

The number of tag bits that this tagged pointer can store. Equal to align_of::<T>().trailing_zeros() (because alignment is always a power of 2, this is the base-2 logarithm of the alignment of T).

Source

pub const MAX_TAG: usize

The maximum tag (inclusive) that this tagged pointer can store. Equal to align_of::<T>() - 1.

Source

pub fn new(ptr: NonNull<T>, tag: usize) -> Self

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

§Panics

This function may panic if ptr is not properly aligned (i.e., aligned to at least align_of::<T>()).

Source

pub unsafe fn new_unchecked(ptr: NonNull<T>, tag: usize) -> Self

Equivalent to Self::new but without some runtime checks.

§Safety
Source

pub unsafe fn new_unchecked_dereferenceable(ptr: NonNull<T>, tag: usize) -> Self

Like Self::new_unchecked, but the pointer must be dereferenceable, which allows better optimization.

§Safety

All conditions of Self::new_unchecked must be upheld, plus ptr must be “dereferenceable” in the sense defined by core::ptr.

Source§

impl<T> TaggedPtr<T>

Source

pub fn get(self) -> (NonNull<T>, usize)

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.

Source

pub fn ptr(self) -> NonNull<T>

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

Source

pub fn set_ptr(&mut self, ptr: NonNull<T>)

Sets the pointer without modifying the tag.

This method is simply equivalent to:

*self = Self::new(ptr, self.tag());

See Self::new for information on argument validity and panics.

Source

pub fn tag(self) -> usize

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

Source

pub fn set_tag(&mut self, tag: usize)

Sets the tag without modifying the pointer.

This method is simply equivalent to:

*self = Self::new(self.ptr(), tag);

See Self::new for more information.

Trait Implementations§

Source§

impl<T> Clone for TaggedPtr<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for TaggedPtr<T>

Source§

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

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

impl<T> Hash for TaggedPtr<T>

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> Ord for TaggedPtr<T>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T> PartialEq for TaggedPtr<T>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T> PartialOrd for TaggedPtr<T>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

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

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> Copy for TaggedPtr<T>

Source§

impl<T> Eq for TaggedPtr<T>

Auto Trait Implementations§

§

impl<T> Freeze for TaggedPtr<T>

§

impl<T> RefUnwindSafe for TaggedPtr<T>
where T: RefUnwindSafe,

§

impl<T> !Send for TaggedPtr<T>

§

impl<T> !Sync for TaggedPtr<T>

§

impl<T> Unpin for TaggedPtr<T>

§

impl<T> UnwindSafe for TaggedPtr<T>
where T: RefUnwindSafe,

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, 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.