Skip to content

Commit e2e4e8e

Browse files
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>
1 parent a796d53 commit e2e4e8e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

crates/bevy_ecs/src/system/system_param.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,35 @@ use std::{
3636
/// Derived `SystemParam` structs may have two lifetimes: `'w` for data stored in the [`World`],
3737
/// and `'s` for data stored in the parameter's state.
3838
///
39+
/// The following list shows the most common [`SystemParam`]s and which lifetime they require
40+
///
41+
/// ```
42+
/// # use bevy_ecs::prelude::*;
43+
/// # #[derive(Resource)]
44+
/// # struct SomeResource;
45+
/// # #[derive(Event)]
46+
/// # struct SomeEvent;
47+
/// # #[derive(Resource)]
48+
/// # struct SomeOtherResource;
49+
/// # use bevy_ecs::system::SystemParam;
50+
/// # #[derive(SystemParam)]
51+
/// # struct ParamsExample<'w, 's> {
52+
/// # query:
53+
/// Query<'w, 's, Entity>,
54+
/// # res:
55+
/// Res<'w, SomeResource>,
56+
/// # res_mut:
57+
/// ResMut<'w, SomeOtherResource>,
58+
/// # local:
59+
/// Local<'s, u8>,
60+
/// # commands:
61+
/// Commands<'w, 's>,
62+
/// # eventreader:
63+
/// EventReader<'w, 's, SomeEvent>,
64+
/// # eventwriter:
65+
/// EventWriter<'w, SomeEvent>
66+
/// # }
67+
///```
3968
/// ## `PhantomData`
4069
///
4170
/// [`PhantomData`] is a special type of `SystemParam` that does nothing.

0 commit comments

Comments
 (0)