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>
impl<'a, T> TaggedRef<'a, T>
Sourcepub fn new(reference: &'a T, tag: usize) -> Self
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>
impl<T> TaggedRef<'_, T>
Sourcepub const BITS: u32 = TaggedPtr<T>::BITS
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§impl<'a, T> TaggedRef<'a, T>
impl<'a, T> TaggedRef<'a, T>
Sourcepub unsafe fn new_unchecked(reference: &'a T, tag: usize) -> Self
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
.
Sourcepub fn get_ref(self) -> &'a T
pub fn get_ref(self) -> &'a T
Gets the reference stored by the tagged reference, without the tag.
Equivalent to self.get().0
.
Sourcepub fn set_ref(&mut self, reference: &'a T)
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.
Sourcepub fn with_ref(self, reference: &T) -> TaggedRef<'_, T>
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())
Sourcepub fn tag(self) -> usize
pub fn tag(self) -> usize
Gets the tag stored by the tagged reference. Equivalent to
self.get().1
.