forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements std::ops operator traits for Mut.
# Objective No one likes how tuple structs and Mut force you to write things like: health.0 += 10; # Solution Implement AddAssign on Mut. impl <'a, T, U> AddAssign<U> for Mut<'a, T> where T: AddAssign<U> { fn add_assign(&mut self, rhs: U) { *self.value += rhs; } } then in our game impl AddAssign<u32> for Health { fn add_assign(&mut self, rhs: u32) { self.0 += rhs.0; } } pub fn health_system( mut query: Query<&mut Health> ) { query.for_each_mut(|mut health| { health += 10; }); }
- Loading branch information
Showing
1 changed file
with
240 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters