Struct TaggedMutRef

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

Mutable version of TaggedRef.

This type behaves like crate::TaggedMutRef 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> TaggedMutRef<'a, T>

Source

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

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

Source§

impl<T> TaggedMutRef<'_, 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> TaggedMutRef<'a, T>

Source

pub unsafe fn new_unchecked(reference: &'a mut 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 to_tagged_ref(&self) -> TaggedRef<'_, T>

Creates an immutable TaggedRef with the same reference and tag.

This method reborrows the reference; see also Self::into_tagged_ref, which preserves the lifetime.

Source

pub fn into_tagged_ref(self) -> TaggedRef<'a, T>

Converts the tagged reference into an immutable TaggedRef.

Self::to_tagged_ref reborrows the reference instead of consuming the TaggedMutRef.

Source

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

Returns an immutable reborrow of the reference stored by the tagged reference, along with a copy of the tag.

See Self::get_mut if you need a mutable reference.

Source

pub fn get_mut(&mut self) -> (&mut T, usize)

Returns a mutable reborrow of the reference stored by the tagged reference, along with a copy of the tag.

Source

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

Deconstructs the tagged reference into its constituent parts: the reference (with the original lifetime 'a) and the tag.

Source

pub fn get_ref(&self) -> &T

Returns an immutable reborrow of the reference stored by the tagged reference.

See Self::get_mut_ref if you need a mutable reference.

Source

pub fn get_mut_ref(&mut self) -> &mut T

Returns a mutable reborrow of the reference stored by the tagged reference.

Source

pub fn into_ref(self) -> &'a mut T

Gets the reference stored by the tagged reference with its original lifetime ('a), consuming the tagged reference in the process.

Equivalent to Self::into_inner().0.

Source

pub fn set_ref(&mut self, reference: &'a mut 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<'b>(&self, reference: &'b mut T) -> TaggedMutRef<'b, T>

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

This method is equivalent to:

TaggedMutRef::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 behaves like the following, but it doesn’t require ownership of the tagged reference:

// Error: can't call `into_ref` on `&mut Self`.
*self = Self::new(self.into_ref(), tag);
Source

pub fn reborrow(&mut self) -> TaggedMutRef<'_, T>

Creates a new tagged reference that reborrows the referenced data with a different lifetime.

This method is equivalent to:

let (reference, tag) = self.get_mut();
TaggedMutRef::new(reference, tag)

Trait Implementations§

Source§

impl<T> AsMut<T> for TaggedMutRef<'_, T>

Source§

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

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

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

Source§

fn as_ref(&self) -> &T

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

impl<T> Debug for TaggedMutRef<'_, 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 TaggedMutRef<'_, 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 TaggedMutRef<'_, 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 TaggedMutRef<'_, 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 TaggedMutRef<'_, 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 TaggedMutRef<'_, T>

Source§

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

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

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

Source§

impl<T> Send for TaggedMutRef<'_, T>
where T: Send,

Source§

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

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<'a, T> !UnwindSafe for TaggedMutRef<'a, T>

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