Skip to content

Commit

Permalink
condense impls
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanSWard committed Jun 29, 2021
1 parent 1cf6ebd commit 64546c4
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions crates/bevy_ecs/src/system/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,7 @@ macro_rules! impl_fallible_commands {
#[inline]
#[allow(dead_code)]
fn return_unit(&self) {}
}

impl<'a, C, T> $name<'a, C, T>
where
C: FallibleCommand,
C::Error: Debug,
T: AddCommand,
{
/// If the command failed, run the provided `error_handler`.
///
/// ## Note
Expand All @@ -167,6 +160,7 @@ macro_rules! impl_fallible_commands {
/// commands.spawn().insert(42).on_err(|error, ctx| {});
/// }
/// ```
#[inline]
pub fn on_err(
&mut self,
error_handler: impl FnOnce(C::Error, CommandContext) + Send + Sync + 'static,
Expand All @@ -188,9 +182,13 @@ macro_rules! impl_fallible_commands {
C: FallibleCommand,
T: AddCommand,
{
#[inline]
fn drop(&mut self) {
if self.command.is_some() {
self.on_err(CommandErrorHandler::log);
if let Some(command) = self.command.take() {
self.inner.add_command(HandledErrorCommand {
command,
error_handler: CommandErrorHandler::log,
});
}
}
}
Expand Down

0 comments on commit 64546c4

Please sign in to comment.