Add a method for converting MutUntyped -> Mut<T> (#7113)

# Objective

`MutUntyped` is a struct that stores a `PtrMut` alongside change tick metadata. Working with this type is cumbersome, and has few benefits over storing the pointer and change ticks separately.

Related: #6430 (title is out of date)

## Solution

Add a convenience method for transforming an untyped change detection pointer into its typed counterpart.

---

## Changelog

- Added the method `MutUntyped::with_type`.
This commit is contained in:
JoJoJet 2023-01-11 17:47:54 +00:00
parent 15ee98db8d
commit 59751d6e33

View file

@ -635,6 +635,17 @@ impl<'a> MutUntyped<'a> {
pub fn as_ref(&self) -> Ptr<'_> {
self.value.as_ref()
}
/// Transforms this [`MutUntyped`] into a [`Mut<T>`] with the same lifetime.
///
/// # Safety
/// - `T` must be the erased pointee type for this [`MutUntyped`].
pub unsafe fn with_type<T>(self) -> Mut<'a, T> {
Mut {
value: self.value.deref_mut(),
ticks: self.ticks,
}
}
}
impl<'a> DetectChanges for MutUntyped<'a> {