bevy icon indicating copy to clipboard operation
bevy copied to clipboard

Implement `std::fmt::Debug` for `ecs::observer::Trigger`

Open Sorseg opened this issue 1 year ago • 4 comments

Objective

I tried writing something like this in my project

.observe(|e: Trigger<OnAdd, Skeleton>| {
    panic!("Skeletoned! {e:?}");
});

and it didn't compile. Having Debug trait defined on Trigger event will ease debugging the observers a little bit.

Solution

Add a bespoke Debug implementation when both the bundle and the event have Debug implemented for them.

Testing

I've added println!("{trigger:#?}"); to the observers example and it compiled!

Caveats with this PR are:

  • removing this implementation if for any reason we will need it, will be a breaking change
  • the implementation is manually generated, which adds potential toil when changing the Trigger structure

Showcase

Log output:

on_add_mine: Trigger {
    event: OnAdd,
    propagate: false,
    trigger: ObserverTrigger {
        observer: 2v1#4294967298,
        event_type: ComponentId(
            0,
        ),
        entity: 454v1#4294967750,
    },
    _marker: PhantomData<observers::Mine>,
}

Thank you for maintaining this engine! :orange_heart:

Sorseg avatar Aug 21 '24 21:08 Sorseg

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

github-actions[bot] avatar Aug 21 '24 21:08 github-actions[bot]

Looks like we added (almost) the same labels at the same time 😅 @MrGVSV

mnmaita avatar Aug 21 '24 21:08 mnmaita

I can fix the doctest some time tomorrow

Sorseg avatar Aug 23 '24 17:08 Sorseg

Doctests for bevy_ecs are run separately, bevy_ecs doesn't depend on bevy, meaning it doesn't have access to the DefaultPlugins.

I tried to use the minimal startup_system example, but bevy_ecs doesn't have access to bevy_app either.

I think the doctest in its current form does not provide value, as it is impossible to make it compile while still looking as regular bevy code. I'll remove it

Sorseg avatar Aug 24 '24 11:08 Sorseg