Open
Description
What problem does this solve or what need does it fill?
Not all Event
types can work well when targeted at an entity, or not targeted at an entity. This can end up surprising to users of these event types when they don't read the event's documentation about this, or if the documentation doesn't exist in the first place.
What solution would you like?
Allow Events to opt out of having a target or not having a target by providing two new subtraits:
trait TargetedEvent: Event {}
trait UntargetedEvent: Event {}
That are automatically implemented by default for a given type when using #[derive(Event)]
, but can be opted out of via a macro attribute:
#[derive(Event)]
#[event(untargeted = false)] // Opt out of untargeted, aka Commands::trigger
#[event(targeted = false)] // Opt out of targeted, aka Commands::trigger_targets
struct MyEvent {
}
Then, Commands
/World
/etc should have their related signatures updated to be:
impl Commands {
pub fn trigger(&mut self, event: impl UntargetedEvent);
pub fn trigger_targets(&mut self, event: impl TargetedEvent, targets: impl TriggerTargets);
}
What alternative(s) have you considered?
Add documentation to all event types that are used with observers.