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>
impl<'a, T> TaggedMutRef<'a, T>
Sourcepub fn new(reference: &'a mut T, tag: usize) -> Self
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>
impl<T> TaggedMutRef<'_, 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> TaggedMutRef<'a, T>
impl<'a, T> TaggedMutRef<'a, T>
Sourcepub unsafe fn new_unchecked(reference: &'a mut T, tag: usize) -> Self
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
.
Sourcepub fn to_tagged_ref(&self) -> TaggedRef<'_, T>
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.
Sourcepub fn into_tagged_ref(self) -> TaggedRef<'a, T>
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
.
Sourcepub fn get(&self) -> (&T, usize)
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.
Sourcepub fn get_mut(&mut self) -> (&mut T, usize)
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.
Sourcepub fn into_inner(self) -> (&'a mut T, usize)
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.
Sourcepub fn get_ref(&self) -> &T
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.
Sourcepub fn get_mut_ref(&mut self) -> &mut T
pub fn get_mut_ref(&mut self) -> &mut T
Returns a mutable reborrow of the reference stored by the tagged reference.
Sourcepub fn into_ref(self) -> &'a mut T
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
.
Sourcepub fn set_ref(&mut self, reference: &'a mut T)
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.
Sourcepub fn with_ref<'b>(&self, reference: &'b mut T) -> TaggedMutRef<'b, T>
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())
Sourcepub fn tag(&self) -> usize
pub fn tag(&self) -> usize
Gets the tag stored by the tagged reference. Equivalent to
self.get().1
.
Sourcepub fn set_tag(&mut self, tag: usize)
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);
Sourcepub fn reborrow(&mut self) -> TaggedMutRef<'_, T>
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)