From fa449e62679592509b390c67f68bd77a8e3643e4 Mon Sep 17 00:00:00 2001 From: Joel Singh Date: Thu, 12 Jun 2025 20:46:11 -0400 Subject: [PATCH] Add example to `Single` docs (#19461) (#19603) # Objective - Add example to `Single` docs, highlighting that you can use methods and properties directly. - Fixes #19461 ## Solution - Added example to inline docs of `Single` ## Testing - `cargo test --doc` - `cargo doc --open` --------- Co-authored-by: Alice Cecile --- crates/bevy_ecs/src/system/query.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/bevy_ecs/src/system/query.rs b/crates/bevy_ecs/src/system/query.rs index a8d6ecf8a8..dfc07d23f1 100644 --- a/crates/bevy_ecs/src/system/query.rs +++ b/crates/bevy_ecs/src/system/query.rs @@ -2573,6 +2573,21 @@ impl<'w, 'q, Q: QueryData, F: QueryFilter> From<&'q mut Query<'w, '_, Q, F>> /// See [`Query`] for more details. /// /// [System parameter]: crate::system::SystemParam +/// +/// # Example +/// ``` +/// # use bevy_ecs::prelude::*; +/// #[derive(Component)] +/// struct Boss { +/// health: f32 +/// }; +/// +/// fn hurt_boss(mut boss: Single<&mut Boss>) { +/// boss.health -= 4.0; +/// } +/// ``` +/// Note that because [`Single`] implements [`Deref`] and [`DerefMut`], methods and fields like `health` can be accessed directly. +/// You can also access the underlying data manually, by calling `.deref`/`.deref_mut`, or by using the `*` operator. pub struct Single<'w, D: QueryData, F: QueryFilter = ()> { pub(crate) item: D::Item<'w>, pub(crate) _filter: PhantomData,