Skip to content

Commit 23dbcf9

Browse files
authored
impl Default for StateScoped<S: Default> (#17401)
This allows this: ```rust #[derive(Component)] #[require(StateScoped<MyState>(StateScoped(MyState)))] struct ComponentA; ``` To be shortened to this: ```rust #[derive(Component)] #[require(StateScoped<MyState>)] struct ComponentA; ``` When `MyState` implements `Default`. Signed-off-by: Jean Mertz <[email protected]>
1 parent 14a955c commit 23dbcf9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

crates/bevy_state/src/state_scoped.rs

+9
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ use crate::state::{StateTransitionEvent, States};
6060
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Component))]
6161
pub struct StateScoped<S: States>(pub S);
6262

63+
impl<S> Default for StateScoped<S>
64+
where
65+
S: States + Default,
66+
{
67+
fn default() -> Self {
68+
Self(S::default())
69+
}
70+
}
71+
6372
/// Removes entities marked with [`StateScoped<S>`]
6473
/// when their state no longer matches the world state.
6574
///

0 commit comments

Comments
 (0)