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 <alice.i.cecile@gmail.com>
This commit is contained in:
Joel Singh 2025-06-12 20:46:11 -04:00 committed by GitHub
parent 2961f44dcd
commit fa449e6267
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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<F>,