Skip to content

Commit

Permalink
use FnOnce in Commands and ChildBuilder where possible (#535)
Browse files Browse the repository at this point in the history
use FnOnce in Commands and ChildBuilder
  • Loading branch information
HyperLightKitsune authored Sep 21, 2020
1 parent 18a8532 commit 295e1f0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 14 deletions.
2 changes: 1 addition & 1 deletion crates/bevy_ecs/src/system/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl Commands {
commands.current_entity
}

pub fn for_current_entity(&mut self, mut f: impl FnMut(Entity)) -> &mut Self {
pub fn for_current_entity(&mut self, f: impl FnOnce(Entity)) -> &mut Self {
{
let commands = self.commands.lock();
let current_entity = commands
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_transform/src/hierarchy/child_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<'a> ChildBuilder<'a> {
self
}

pub fn for_current_entity(&mut self, mut func: impl FnMut(Entity)) -> &mut Self {
pub fn for_current_entity(&mut self, func: impl FnOnce(Entity)) -> &mut Self {
let current_entity = self
.commands
.current_entity
Expand All @@ -105,13 +105,13 @@ impl<'a> ChildBuilder<'a> {
}

pub trait BuildChildren {
fn with_children(&mut self, f: impl FnMut(&mut ChildBuilder)) -> &mut Self;
fn with_children(&mut self, f: impl FnOnce(&mut ChildBuilder)) -> &mut Self;
fn push_children(&mut self, parent: Entity, children: &[Entity]) -> &mut Self;
fn insert_children(&mut self, parent: Entity, index: usize, children: &[Entity]) -> &mut Self;
}

impl BuildChildren for Commands {
fn with_children(&mut self, mut parent: impl FnMut(&mut ChildBuilder)) -> &mut Self {
fn with_children(&mut self, parent: impl FnOnce(&mut ChildBuilder)) -> &mut Self {
{
let mut commands = self.commands.lock();
let current_entity = commands.current_entity.expect("Cannot add children because the 'current entity' is not set. You should spawn an entity first.");
Expand Down Expand Up @@ -159,7 +159,7 @@ impl BuildChildren for Commands {
}

impl<'a> BuildChildren for ChildBuilder<'a> {
fn with_children(&mut self, mut spawn_children: impl FnMut(&mut ChildBuilder)) -> &mut Self {
fn with_children(&mut self, spawn_children: impl FnOnce(&mut ChildBuilder)) -> &mut Self {
let current_entity = self.commands.current_entity.expect("Cannot add children because the 'current entity' is not set. You should spawn an entity first.");
self.commands.current_entity = None;
let push_children = {
Expand Down
12 changes: 3 additions & 9 deletions crates/bevy_transform/src/hierarchy/world_child_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,11 @@ impl<'a, 'b> WorldChildBuilder<'a, 'b> {
}

pub trait BuildWorldChildren {
fn with_children(&mut self, spawn_children: impl FnMut(&mut WorldChildBuilder)) -> &mut Self;
fn with_children(&mut self, spawn_children: impl FnOnce(&mut WorldChildBuilder)) -> &mut Self;
}

impl<'a> BuildWorldChildren for WorldBuilder<'a> {
fn with_children(
&mut self,
mut spawn_children: impl FnMut(&mut WorldChildBuilder),
) -> &mut Self {
fn with_children(&mut self, spawn_children: impl FnOnce(&mut WorldChildBuilder)) -> &mut Self {
{
let current_entity = self.current_entity.expect("Cannot add children because the 'current entity' is not set. You should spawn an entity first.");
let mut builder = WorldChildBuilder {
Expand All @@ -72,10 +69,7 @@ impl<'a> BuildWorldChildren for WorldBuilder<'a> {
}

impl<'a, 'b> BuildWorldChildren for WorldChildBuilder<'a, 'b> {
fn with_children(
&mut self,
mut spawn_children: impl FnMut(&mut WorldChildBuilder),
) -> &mut Self {
fn with_children(&mut self, spawn_children: impl FnOnce(&mut WorldChildBuilder)) -> &mut Self {
let current_entity = self
.world_builder
.current_entity
Expand Down

0 comments on commit 295e1f0

Please sign in to comment.