Skip to content

Commit f5ae85c

Browse files
committed
coalesce error handler param into CommandError
1 parent ac6f084 commit f5ae85c

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

crates/bevy_ecs/src/system/commands/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::world::World;
21
use std::{
32
fmt::Debug,
43
ops::{Deref, DerefMut},
@@ -94,7 +93,7 @@ macro_rules! impl_fallible_commands {
9493
{
9594
pub fn on_failure<'this, H>(&'this mut self, error_handler: H) -> $returnty
9695
where
97-
H: FnOnce(C::Error, &mut World) + Send + Sync + 'static,
96+
H: FnOnce(CommandError<'_, C>) + Send + Sync + 'static,
9897
{
9998
let command = self.command.take().unwrap();
10099
self.inner.add_command(FallibleCommandWrapper {

crates/bevy_ecs/src/system/commands/fallible.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ use crate::world::World;
33
use bevy_utils::tracing::error;
44
use std::fmt::Debug;
55

6+
pub struct CommandError<'a, C: FallibleCommand> {
7+
pub error: C::Error,
8+
pub world: &'a mut World,
9+
}
10+
611
pub trait FallibleCommand: Send + Sync + 'static {
712
type Error;
813

@@ -55,7 +60,7 @@ where
5560
pub(crate) struct FallibleCommandWrapper<C, E>
5661
where
5762
C: FallibleCommand,
58-
E: FnOnce(C::Error, &mut World) + Send + Sync + 'static,
63+
E: FnOnce(CommandError<'_, C>) + Send + Sync + 'static,
5964
{
6065
pub(crate) command: C,
6166
pub(crate) error_handler: E,
@@ -64,16 +69,16 @@ where
6469
impl<C, E> Command for FallibleCommandWrapper<C, E>
6570
where
6671
C: FallibleCommand,
67-
E: FnOnce(C::Error, &mut World) + Send + Sync + 'static,
72+
E: FnOnce(CommandError<'_, C>) + Send + Sync + 'static,
6873
{
6974
fn write(self: Box<Self>, world: &mut World) {
7075
let FallibleCommandWrapper {
7176
command,
7277
error_handler,
7378
} = *self;
7479

75-
if let Err(e) = command.try_write(world) {
76-
(error_handler)(e, world);
80+
if let Err(error) = command.try_write(world) {
81+
(error_handler)(CommandError { error, world });
7782
}
7883
}
7984
}

crates/bevy_ecs/src/system/commands/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::{
77
entity::{Entities, Entity},
88
world::World,
99
};
10-
use config::*;
1110
use fallible::*;
1211
use std::{fmt::Debug, marker::PhantomData};
1312

@@ -732,7 +731,7 @@ mod tests {
732731

733732
let mut try_despawn = |e| {
734733
let invoked_clone = invoked.clone();
735-
commands.entity(e).despawn().on_failure(move |_, _| {
734+
commands.entity(e).despawn().on_failure(move |_| {
736735
invoked_clone.fetch_add(1, Ordering::Relaxed);
737736
});
738737
};

0 commit comments

Comments
 (0)