Struct TaggedRef

Source
pub struct TaggedRef<'a, T>(/* private fields */);
Expand description

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

This type behaves like crate::TaggedRef 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 a reference to T; see Self::BITS for the exact calculation.

Implementations§

Source§

impl<'a, T> TaggedRef<'a, T>

Source

pub fn new(reference: &'a T, tag: usize) -> Self

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

Source§

impl<T> TaggedRef<'_, T>

Source

pub const BITS: u32 = TaggedPtr<T>::BITS

The number of tag bits that this tagged reference 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 = TaggedPtr<T>::MAX_TAG

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

Source§

impl<'a, T> TaggedRef<'a, T>

Source

pub unsafe fn new_unchecked(reference: &'a T, tag: usize) -> Self

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

§Safety

tag cannot be greater than Self::MAX_TAG.

Source

pub fn get(self) -> (&'a T, usize)

Gets the reference and tag stored by the tagged reference.

Source

pub fn get_ref(self) -> &'a T

Gets the reference stored by the tagged reference, without the tag.

Equivalent to self.get().0.

Source

pub fn set_ref(&mut self, reference: &'a T)

Sets the reference without modifying the tag.

This method is equivalent to:

*self = self.with_ref(reference);

Because this method mutates the tagged reference in-place, the new reference must have the exact same lifetime, 'a. As a consequence, any data currently borrowed for 'a by the old reference will remain borrowed even once the reference is updated.

Self::with_ref may be more flexible in some situations, as it returns a new tagged reference that can have a different lifetime.

Source

pub fn with_ref(self, reference: &T) -> TaggedRef<'_, T>

Creates a new tagged reference with the same tag but a different reference.

This method is equivalent to:

TaggedRef::new(reference, self.tag())
Source

pub fn tag(self) -> usize

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

Source

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

Sets the tag without modifying the reference.

This method is equivalent to:

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

Trait Implementations§

Source§

impl<T> AsRef<T> for TaggedRef<'_, T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> Clone for TaggedRef<'_, 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 TaggedRef<'_, T>
where T: Debug,

Source§

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

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

impl<T> Hash for TaggedRef<'_, T>
where T: Hash,

Source§

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

Hashes self.get().

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 TaggedRef<'_, T>
where T: Ord,

Source§

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

Returns self.get().cmp(&other.get()).

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 TaggedRef<'_, T>
where T: PartialEq,

Source§

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

Returns self.get() == other.get().

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 TaggedRef<'_, T>
where T: PartialOrd,

Source§

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

Returns self.get().partial_cmp(&other.get()).

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> Pointer for TaggedRef<'_, T>

Source§

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

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

impl<T> Copy for TaggedRef<'_, T>

Source§

impl<T> Eq for TaggedRef<'_, T>
where T: Eq,

Source§

impl<T> Send for TaggedRef<'_, T>
where T: Sync,

Source§

impl<T> Sync for TaggedRef<'_, T>
where T: Sync,

Auto Trait Implementations§

§

impl<'a, T> Freeze for TaggedRef<'a, T>

§

impl<'a, T> RefUnwindSafe for TaggedRef<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Unpin for TaggedRef<'a, T>

§

impl<'a, T> UnwindSafe for TaggedRef<'a, 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.