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 <git@jeanmertz.com>
This commit is contained in:
Jean Mertz 2025-01-17 02:19:09 +01:00 committed by GitHub
parent 14a955c5eb
commit 23dbcf9215
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -60,6 +60,15 @@ use crate::state::{StateTransitionEvent, States};
#[cfg_attr(feature = "bevy_reflect", derive(Reflect), reflect(Component))]
pub struct StateScoped<S: States>(pub S);
impl<S> Default for StateScoped<S>
where
S: States + Default,
{
fn default() -> Self {
Self(S::default())
}
}
/// Removes entities marked with [`StateScoped<S>`]
/// when their state no longer matches the world state.
///