Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions crates/bevy_ecs/src/system/commands/entity_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use crate::{
};
use bevy_ptr::{move_as_ptr, OwningPtr};

use bevy_platform::sync::Arc;

/// A command which gets executed for a given [`Entity`].
///
/// Should be used with [`EntityCommands::queue`](crate::system::EntityCommands::queue).
Expand Down Expand Up @@ -127,6 +129,18 @@ where
}
}

impl<Out, F> EntityCommand for Arc<F>
where
F: Fn(EntityWorldMut) -> Out + Send + Sync + ?Sized + 'static,
Out: EntityCommandOutput + 'static,
{
type Out = Out;

fn apply(self, entity: EntityWorldMut) -> Self::Out {
self(entity)
}
}

/// An [`EntityCommand`] that adds the components in a [`Bundle`] to an entity.
#[track_caller]
pub fn insert(bundle: impl Bundle, mode: InsertMode) -> impl EntityCommand {
Expand Down