diff --git a/crates/bevy_ecs/src/system/commands/mod.rs b/crates/bevy_ecs/src/system/commands/mod.rs index fb0f1b388f..8a4a81dbc3 100644 --- a/crates/bevy_ecs/src/system/commands/mod.rs +++ b/crates/bevy_ecs/src/system/commands/mod.rs @@ -444,9 +444,7 @@ impl<'w, 's> Commands<'w, 's> { /// # bevy_ecs::system::assert_is_system(initialise_scoreboard); /// ``` pub fn init_resource(&mut self) { - self.queue.push(InitResource:: { - _phantom: PhantomData::::default(), - }); + self.queue.push(InitResource::::new()); } /// Pushes a [`Command`] to the queue for inserting a [`Resource`] in the [`World`] with a specific value. @@ -499,9 +497,7 @@ impl<'w, 's> Commands<'w, 's> { /// # bevy_ecs::system::assert_is_system(system); /// ``` pub fn remove_resource(&mut self) { - self.queue.push(RemoveResource:: { - phantom: PhantomData, - }); + self.queue.push(RemoveResource::::new()); } /// Pushes a generic [`Command`] to the command queue. @@ -748,10 +744,7 @@ impl<'w, 's, 'a> EntityCommands<'w, 's, 'a> { where T: Bundle, { - self.commands.add(Remove:: { - entity: self.entity, - phantom: PhantomData, - }); + self.commands.add(Remove::::new(self.entity)); self } @@ -956,6 +949,16 @@ where } } +impl Remove { + /// Creates a [`Command`] which will remove the specified [`Entity`] when flushed + pub const fn new(entity: Entity) -> Self { + Self { + entity, + phantom: PhantomData::, + } + } +} + pub struct InitResource { _phantom: PhantomData, } @@ -966,6 +969,15 @@ impl Command for InitResource { } } +impl InitResource { + /// Creates a [`Command`] which will insert a default created [`Resource`] into the [`World`] + pub const fn new() -> Self { + Self { + _phantom: PhantomData::, + } + } +} + pub struct InsertResource { pub resource: R, } @@ -986,6 +998,15 @@ impl Command for RemoveResource { } } +impl RemoveResource { + /// Creates a [`Command`] which will remove a [`Resource`] from the [`World`] + pub const fn new() -> Self { + Self { + phantom: PhantomData::, + } + } +} + /// [`Command`] to log the components of a given entity. See [`EntityCommands::log_components`]. pub struct LogComponents { entity: Entity,