document which lifetime is needed for systemparam derive (#11321)
# Objective Document a few common cases of which lifetime is required when using SystemParam Derive ## Solution Added a table in the doc comment --------- Co-authored-by: laund <me@laund.moe> Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
This commit is contained in:
parent
a796d53a05
commit
e2e4e8eb9a
@ -36,6 +36,35 @@ use std::{
|
||||
/// Derived `SystemParam` structs may have two lifetimes: `'w` for data stored in the [`World`],
|
||||
/// and `'s` for data stored in the parameter's state.
|
||||
///
|
||||
/// The following list shows the most common [`SystemParam`]s and which lifetime they require
|
||||
///
|
||||
/// ```
|
||||
/// # use bevy_ecs::prelude::*;
|
||||
/// # #[derive(Resource)]
|
||||
/// # struct SomeResource;
|
||||
/// # #[derive(Event)]
|
||||
/// # struct SomeEvent;
|
||||
/// # #[derive(Resource)]
|
||||
/// # struct SomeOtherResource;
|
||||
/// # use bevy_ecs::system::SystemParam;
|
||||
/// # #[derive(SystemParam)]
|
||||
/// # struct ParamsExample<'w, 's> {
|
||||
/// # query:
|
||||
/// Query<'w, 's, Entity>,
|
||||
/// # res:
|
||||
/// Res<'w, SomeResource>,
|
||||
/// # res_mut:
|
||||
/// ResMut<'w, SomeOtherResource>,
|
||||
/// # local:
|
||||
/// Local<'s, u8>,
|
||||
/// # commands:
|
||||
/// Commands<'w, 's>,
|
||||
/// # eventreader:
|
||||
/// EventReader<'w, 's, SomeEvent>,
|
||||
/// # eventwriter:
|
||||
/// EventWriter<'w, SomeEvent>
|
||||
/// # }
|
||||
///```
|
||||
/// ## `PhantomData`
|
||||
///
|
||||
/// [`PhantomData`] is a special type of `SystemParam` that does nothing.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user