From b0cc6bfd7ef0c82a306cfcfa15f16463774a8e7c Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Wed, 22 Nov 2023 20:20:39 +0000 Subject: [PATCH] Rustdoc example for Ref (#10682) --- crates/bevy_ecs/src/change_detection.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/bevy_ecs/src/change_detection.rs b/crates/bevy_ecs/src/change_detection.rs index 0e6483600b..27a6c08c1c 100644 --- a/crates/bevy_ecs/src/change_detection.rs +++ b/crates/bevy_ecs/src/change_detection.rs @@ -623,6 +623,28 @@ impl<'a, T: 'static> From> for Mut<'a, T> { /// Shared borrow of an entity's component with access to change detection. /// Similar to [`Mut`] but is immutable and so doesn't require unique access. +/// +/// # Examples +/// +/// These two systems produce the same output. +/// +/// ``` +/// # use bevy_ecs::change_detection::DetectChanges; +/// # use bevy_ecs::query::{Changed, With}; +/// # use bevy_ecs::system::Query; +/// # use bevy_ecs::world::Ref; +/// # use bevy_ecs_macros::Component; +/// # #[derive(Component)] +/// # struct MyComponent; +/// +/// fn how_many_changed_1(query: Query<(), Changed>) { +/// println!("{} changed", query.iter().count()); +/// } +/// +/// fn how_many_changed_2(query: Query>) { +/// println!("{} changed", query.iter().filter(|c| c.is_changed()).count()); +/// } +/// ``` pub struct Ref<'a, T: ?Sized> { pub(crate) value: &'a T, pub(crate) ticks: Ticks<'a>,