pub struct TaggedMutRef<'a, T, const BITS: usize>(/* private fields */);
Expand description
Mutable version of TaggedRef
.
Like TaggedRef
, this type stores a reference and an integer tag,
but the reference in this type is mutable.
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 T
1,
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> TaggedMutRef<'a, T, BITS>
impl<'a, T, const BITS: usize> TaggedMutRef<'a, T, BITS>
Source§impl<T, const BITS: usize> TaggedMutRef<'_, T, BITS>
impl<T, const BITS: usize> TaggedMutRef<'_, T, BITS>
Source§impl<'a, T, const BITS: usize> TaggedMutRef<'a, T, BITS>
impl<'a, T, const BITS: usize> TaggedMutRef<'a, T, BITS>
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, BITS>
pub fn to_tagged_ref(&self) -> TaggedRef<'_, T, BITS>
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, BITS>
pub fn into_tagged_ref(self) -> TaggedRef<'a, T, BITS>
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, BITS>
pub fn with_ref<'b>(&self, reference: &'b mut T) -> TaggedMutRef<'b, T, BITS>
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, BITS>
pub fn reborrow(&mut self) -> TaggedMutRef<'_, T, BITS>
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)