Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use an opaque type for EntityCommand::with_entity #11210

Merged
merged 9 commits into from
Jun 26, 2024
20 changes: 4 additions & 16 deletions crates/bevy_ecs/src/system/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,26 +647,14 @@ impl<'w, 's> Commands<'w, 's> {
/// ```
pub trait EntityCommand: Send + 'static {
/// Executes this command for the given [`Entity`].
fn apply(self, id: Entity, world: &mut World);
fn apply(self, entity: Entity, world: &mut World);

/// Returns a [`Command`] which executes this [`EntityCommand`] for the given [`Entity`].
fn with_entity(self, id: Entity) -> WithEntity<Self>
fn with_entity(self, entity: Entity) -> impl Command
where
Self: Sized,
{
WithEntity { cmd: self, id }
}
}

/// Turns an [`EntityCommand`] type into a [`Command`] type.
pub struct WithEntity<C: EntityCommand> {
cmd: C,
id: Entity,
}

impl<C: EntityCommand> Command for WithEntity<C> {
#[inline]
fn apply(self, world: &mut World) {
self.cmd.apply(self.id, world);
move |world: &mut World| self.apply(entity, world)
}
}

Expand Down
Loading