Skip to content

Commit 59751d6

Browse files
committed
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`.
1 parent 15ee98d commit 59751d6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

crates/bevy_ecs/src/change_detection.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,17 @@ impl<'a> MutUntyped<'a> {
635635
pub fn as_ref(&self) -> Ptr<'_> {
636636
self.value.as_ref()
637637
}
638+
639+
/// Transforms this [`MutUntyped`] into a [`Mut<T>`] with the same lifetime.
640+
///
641+
/// # Safety
642+
/// - `T` must be the erased pointee type for this [`MutUntyped`].
643+
pub unsafe fn with_type<T>(self) -> Mut<'a, T> {
644+
Mut {
645+
value: self.value.deref_mut(),
646+
ticks: self.ticks,
647+
}
648+
}
638649
}
639650

640651
impl<'a> DetectChanges for MutUntyped<'a> {

0 commit comments

Comments
 (0)