From 076e6f780cdc523d7b2e5bea03aa093227bceb1c Mon Sep 17 00:00:00 2001 From: JoJoJet <21144246+JoJoJet@users.noreply.github.com> Date: Fri, 6 Jan 2023 23:24:25 +0000 Subject: [PATCH] Update an outdated example for `Mut::map_unchanged` (#7115) # Objective - The doctest for `Mut::map_unchanged` uses a fake function `set_if_not_equal` to demonstrate usage. - Now that #6853 has been merged, we can use `Mut::set_if_neq` directly instead of mocking it. --- crates/bevy_ecs/src/change_detection.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/crates/bevy_ecs/src/change_detection.rs b/crates/bevy_ecs/src/change_detection.rs index 10bd2b5da3..d9ce86e602 100644 --- a/crates/bevy_ecs/src/change_detection.rs +++ b/crates/bevy_ecs/src/change_detection.rs @@ -216,20 +216,17 @@ macro_rules! impl_methods { /// /// ```rust /// # use bevy_ecs::prelude::*; - /// # pub struct Vec2; + /// # #[derive(PartialEq)] pub struct Vec2; /// # impl Vec2 { pub const ZERO: Self = Self; } /// # #[derive(Component)] pub struct Transform { translation: Vec2 } - /// # mod my_utils { - /// # pub fn set_if_not_equal(x: bevy_ecs::prelude::Mut, val: T) { unimplemented!() } - /// # } /// // When run, zeroes the translation of every entity. /// fn reset_positions(mut transforms: Query<&mut Transform>) { /// for transform in &mut transforms { /// // We pinky promise not to modify `t` within the closure. /// // Breaking this promise will result in logic errors, but will never cause undefined behavior. - /// let translation = transform.map_unchanged(|t| &mut t.translation); + /// let mut translation = transform.map_unchanged(|t| &mut t.translation); /// // Only reset the translation if it isn't already zero; - /// my_utils::set_if_not_equal(translation, Vec2::ZERO); + /// translation.set_if_neq(Vec2::ZERO); /// } /// } /// # bevy_ecs::system::assert_is_system(reset_positions);