mirror of
https://github.com/bevyengine/bevy
synced 2024-11-22 12:43:34 +00:00
Implement MutUntyped::from(mut_typed) (#12406)
# Objective Allow to create MutUntyped<'a> instance from Mut<'a, T>. Fixes #12405 ## Solution Added impl<'a, T> From<Mut<'a, T>> for MutUntyped<'>
This commit is contained in:
parent
aea9b4a9e4
commit
f0a98645d0
1 changed files with 34 additions and 0 deletions
|
@ -938,6 +938,15 @@ impl std::fmt::Debug for MutUntyped<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'w, T> From<Mut<'w, T>> for MutUntyped<'w> {
|
||||
fn from(value: Mut<'w, T>) -> Self {
|
||||
MutUntyped {
|
||||
value: value.value.into(),
|
||||
ticks: value.ticks,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use bevy_ecs_macros::Resource;
|
||||
|
@ -1254,4 +1263,29 @@ mod tests {
|
|||
|
||||
assert!(new.is_changed());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mut_untyped_from_mut() {
|
||||
let mut component_ticks = ComponentTicks {
|
||||
added: Tick::new(1),
|
||||
changed: Tick::new(2),
|
||||
};
|
||||
let ticks = TicksMut {
|
||||
added: &mut component_ticks.added,
|
||||
changed: &mut component_ticks.changed,
|
||||
last_run: Tick::new(3),
|
||||
this_run: Tick::new(4),
|
||||
};
|
||||
let mut c = C {};
|
||||
let mut_typed = Mut {
|
||||
value: &mut c,
|
||||
ticks,
|
||||
};
|
||||
|
||||
let into_mut: MutUntyped = mut_typed.into();
|
||||
assert_eq!(1, into_mut.ticks.added.get());
|
||||
assert_eq!(2, into_mut.ticks.changed.get());
|
||||
assert_eq!(3, into_mut.ticks.last_run.get());
|
||||
assert_eq!(4, into_mut.ticks.this_run.get());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue