Skip to content

Commit

Permalink
Implement MutUntyped::from(mut_typed)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkb0o committed Mar 10, 2024
1 parent aea9b4a commit 4c8b41f
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions crates/bevy_ecs/src/change_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 4c8b41f

Please sign in to comment.