mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
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:
parent
15ee98db8d
commit
59751d6e33
1 changed files with 11 additions and 0 deletions
|
@ -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> {
|
||||
|
|
Loading…
Reference in a new issue