Repository: bevyengine/bevy
File: crates/bevy_ecs/src/system/commands/mod.rs (Rust)

Code before:
    /// A surprising number of functions meet the trait bounds for `event_fn`:
    ///
    /// ```rust
    /// # use bevy_ecs::prelude::*;
    ///
    /// #[derive(EntityEvent)]
    /// struct Explode(Entity);
    ///
    /// impl From<Entity> for Explode {
    ///    fn from(entity: Entity) -> Self {
    ///       Explode(entity)
    ///    }
    /// }
    ///

    /// fn trigger_via_constructor(mut commands: Commands) {
    ///     // The fact that `Epxlode` is a single-field tuple struct
    ///     // ensures that `Explode(entity)` is a function that generates
    ///     // an EntityEvent, meeting the trait bounds for `event_fn`.
    ///     commands.spawn_empty().trigger(Explode);
    ///
    /// }
    ///
    ///
    /// fn trigger_via_from_trait(mut commands: Commands) {
    ///     commands.spawn_empty().trigger(Explode::from(entity));
    /// }
    ///

    /// fn trigger_via_closure(mut commands: Commands) {
    ///     commands.spawn_empty().trigger(|entity| Explode(entity));
    /// }
    /// ```
    #[track_caller]
    pub fn trigger<'t, E: EntityEvent<Trigger<'t>: Default>>(
        &mut self,
        event_fn: impl FnOnce(Entity) -> E,
    ) -> &mut Self {
        let event = (event_fn)(self.entity);
        self.commands.trigger(event);
        self
    }
}

/// A wrapper around [`EntityCommands`] with convenience methods for working with a specified component type.
pub struct EntityEntryCommands<'a, T> {
    entity_commands: EntityCommands<'a>,
    marker: PhantomData<T>,
}

impl<'a, T: Component<Mutability = Mutable>> EntityEntryCommands<'a, T> {

Review comment (suggestion):
```suggestion
    ///     commands.spawn_empty().trigger(Explode::from);
```

Code after:
    /// A surprising number of functions meet the trait bounds for `event_fn`:
    ///
    /// ```rust
    /// # use bevy_ecs::prelude::*;
    ///
    /// #[derive(EntityEvent)]
    /// struct Explode(Entity);
    ///
    /// impl From<Entity> for Explode {
    ///    fn from(entity: Entity) -> Self {
    ///       Explode(entity)
    ///    }
    /// }
    ///
    ///
    /// fn trigger_via_constructor(mut commands: Commands) {
    ///     // The fact that `Epxlode` is a single-field tuple struct
    ///     // ensures that `Explode(entity)` is a function that generates
    ///     // an EntityEvent, meeting the trait bounds for `event_fn`.
    ///     commands.spawn_empty().trigger(Explode);
    ///
    /// }
    ///
    ///
    /// fn trigger_via_from_trait(mut commands: Commands) {
    ///     // This variant also works for events like `struct Explode { entity: Entity }`
    ///     commands.spawn_empty().trigger(Explode::from);
    /// }
    ///
    /// fn trigger_via_closure(mut commands: Commands) {
    ///     commands.spawn_empty().trigger(|entity| Explode(entity));
    /// }
    /// ```
    #[track_caller]
    pub fn trigger<'t, E: EntityEvent<Trigger<'t>: Default>>(
        &mut self,
        event_fn: impl FnOnce(Entity) -> E,
    ) -> &mut Self {
        let event = (event_fn)(self.entity);
        self.commands.trigger(event);
        self
    }
}

/// A wrapper around [`EntityCommands`] with convenience methods for working with a specified component type.
pub struct EntityEntryCommands<'a, T> {
    entity_commands: EntityCommands<'a>,
    marker: PhantomData<T>,
}

impl<'a, T: Component<Mutability = Mutable>> EntityEntryCommands<'a, T> {