Skip to content

Commit 14a955c

Browse files
authored
Add usage notes for the IntoX family of ECS traits (#17379)
# Objective Occasionally bevy users will want to store systems or observer systems in a component or resource, but they first try to store `IntoSystem` instead of `System`, which leads to some headaches having to deal with the `M` marker type parameter. We should recommend they use the `X` trait instead of the `IntoX` trait in that case, as well for returning from a function. ## Solution Add usage notes to the `IntoX` traits about using `X` instead.
1 parent 3737f86 commit 14a955c

File tree

4 files changed

+30
-0
lines changed

4 files changed

+30
-0
lines changed

crates/bevy_ecs/src/schedule/config.rs

+12
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ impl<T> NodeConfigs<T> {
247247
/// [`SystemParam`](crate::system::SystemParam)), or tuples thereof.
248248
/// It is a common entry point for system configurations.
249249
///
250+
/// # Usage notes
251+
///
252+
/// This trait should only be used as a bound for trait implementations or as an
253+
/// argument to a function. If system configs need to be returned from a
254+
/// function or stored somewhere, use [`SystemConfigs`] instead of this trait.
255+
///
250256
/// # Examples
251257
///
252258
/// ```
@@ -617,6 +623,12 @@ impl SystemSetConfig {
617623
pub type SystemSetConfigs = NodeConfigs<InternedSystemSet>;
618624

619625
/// Types that can convert into a [`SystemSetConfigs`].
626+
///
627+
/// # Usage notes
628+
///
629+
/// This trait should only be used as a bound for trait implementations or as an
630+
/// argument to a function. If system set configs need to be returned from a
631+
/// function or stored somewhere, use [`SystemSetConfigs`] instead of this trait.
620632
#[diagnostic::on_unimplemented(
621633
message = "`{Self}` does not describe a valid system set configuration",
622634
label = "invalid system set configuration"

crates/bevy_ecs/src/schedule/set.rs

+6
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ impl SystemSet for AnonymousSet {
152152
}
153153

154154
/// Types that can be converted into a [`SystemSet`].
155+
///
156+
/// # Usage notes
157+
///
158+
/// This trait should only be used as a bound for trait implementations or as an
159+
/// argument to a function. If a system set needs to be returned from a function
160+
/// or stored somewhere, use [`SystemSet`] instead of this trait.
155161
#[diagnostic::on_unimplemented(
156162
message = "`{Self}` is not a system set",
157163
label = "invalid system set"

crates/bevy_ecs/src/system/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ use crate::world::World;
160160
/// Use this to get a system from a function. Also note that every system implements this trait as
161161
/// well.
162162
///
163+
/// # Usage notes
164+
///
165+
/// This trait should only be used as a bound for trait implementations or as an
166+
/// argument to a function. If a system needs to be returned from a function or
167+
/// stored somewhere, use [`System`] instead of this trait.
168+
///
163169
/// # Examples
164170
///
165171
/// ```

crates/bevy_ecs/src/system/observer_system.rs

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ impl<
2121
}
2222

2323
/// Implemented for systems that convert into [`ObserverSystem`].
24+
///
25+
/// # Usage notes
26+
///
27+
/// This trait should only be used as a bound for trait implementations or as an
28+
/// argument to a function. If an observer system needs to be returned from a
29+
/// function or stored somewhere, use [`ObserverSystem`] instead of this trait.
2430
#[diagnostic::on_unimplemented(
2531
message = "`{Self}` cannot become an `ObserverSystem`",
2632
label = "the trait `IntoObserverSystem` is not implemented",

0 commit comments

Comments
 (0)