pub struct TaggedRef<'a, T, const BITS: usize>(/* private fields */);Expand description
A tagged reference: a space-efficient representation of a reference and integer tag.
This type behaves like TaggedPtr but with a reference instead of
a raw pointer.
BITS specifies how many bits are used for the tag. The alignment
of T must be large enough to store this many bits: if BITS is
larger than the base-2 logarithm of the alignment of T1,
panics or compilation errors will occur.
Because alignment is always a power of 2, this is equal to
align_of::<T>().trailing_zeros(). ↩
Implementations§
Source§impl<'a, T, const BITS: usize> TaggedRef<'a, T, BITS>
impl<'a, T, const BITS: usize> TaggedRef<'a, T, BITS>
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, BITS>
pub fn with_ref(self, reference: &T) -> TaggedRef<'_, T, BITS>
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.