Skip to content

Commit

Permalink
Add a method for converting MutUntyped -> Mut<T> (#7113)
Browse files Browse the repository at this point in the history
# 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`.
  • Loading branch information
JoJoJet committed Jan 11, 2023
1 parent 15ee98d commit 59751d6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/bevy_ecs/src/change_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down

0 comments on commit 59751d6

Please sign in to comment.