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 FnOnce in Commands and ChildBuilder where possible #535

Merged
Merged
Show file tree
Hide file tree
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
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