forked from bevyengine/bevy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Objective When designing an API, you may wish to provide access only to a specific field of a component or resource. The current options for doing this in safe code are * `*Mut::into_inner`, which flags a change no matter what. * `*Mut::bypass_change_detection`, which misses all changes. ## Solution Add the method `map_unchanged`. ### Example ```rust // When run, zeroes the translation of every entity. fn reset_all(mut transforms: Query<&mut Transform>) { for transform in &mut transforms { // We pinky promise not to modify `t` within the closure. let translation = transform.map_unchanged(|t| &mut t.translation); // Only reset the translation if it isn't already zero. translation.set_if_not_equal(Vec2::ZERO); } } ``` --- ## Changelog + Added the method `map_unchanged` to types `Mut<T>`, `ResMut<T>`, and `NonSendMut<T>`.
- Loading branch information
Showing
1 changed file
with
70 additions
and
4 deletions.
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