# 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:
parent
2961f44dcd
commit
fa449e6267
@ -2573,6 +2573,21 @@ impl<'w, 'q, Q: QueryData, F: QueryFilter> From<&'q mut Query<'w, '_, Q, F>>
|
|||||||
/// See [`Query`] for more details.
|
/// See [`Query`] for more details.
|
||||||
///
|
///
|
||||||
/// [System parameter]: crate::system::SystemParam
|
/// [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 struct Single<'w, D: QueryData, F: QueryFilter = ()> {
|
||||||
pub(crate) item: D::Item<'w>,
|
pub(crate) item: D::Item<'w>,
|
||||||
pub(crate) _filter: PhantomData<F>,
|
pub(crate) _filter: PhantomData<F>,
|
||||||
|
Loading…
Reference in New Issue
Block a user