Repository: bevyengine/bevy
File: crates/bevy_ecs/src/world/entity_ref.rs (Rust)

Code before:
        // SAFETY: entity being alive was asserted
        unsafe {
            self.world()
                .entities()
                .entity_get_spawned_or_despawned_unchecked(self.entity)
                .1
        }
    }

    /// Reborrows this entity in a temporary scope.
    /// This is useful for executing a function that requires a `EntityWorldMut`
    /// but you do not want to move out the entity ownership.
    pub fn reborrow_scope<U>(&mut self, f: impl FnOnce(EntityWorldMut) -> U) -> U {
        let Self {
            entity, location, ..
        } = *self;
        self.world_scope(move |world| {
            f(EntityWorldMut {
                world,
                entity,
                location,
            })
        })
    }

    /// Passes the current entity into the given function, and triggers the [`EntityEvent`] returned by that function.
    #[track_caller]
    pub fn trigger<'t, E: EntityEvent<Trigger<'t>: Default>>(
        &mut self,
        event_fn: impl FnOnce(Entity) -> E,
    ) -> &mut Self {
        let mut event = (event_fn)(self.entity);
        let caller = MaybeLocation::caller();
        self.world_scope(|world| {
            world.trigger_ref_with_caller(
                &mut event,
                &mut <E::Trigger<'_> as Default>::default(),
                caller,
            );
        });
        self
    }
}

/// A view into a single entity and component in a world, which may either be vacant or occupied.
///
/// This `enum` can only be constructed from the [`entry`] method on [`EntityWorldMut`].
///
/// [`entry`]: EntityWorldMut::entry
pub enum ComponentEntry<'w, 'a, T: Component> {
    /// An occupied entry.

Review comment (suggestion):
```suggestion
    /// Passes the current entity into the given function, and triggers the [`EntityEvent`] returned by that function.
    /// See [`EntityCommands::trigger`] for usage examples
```

dunno if the doc link will work, maybe that struct is not in scope

Code after:
        // SAFETY: entity being alive was asserted
        unsafe {
            self.world()
                .entities()
                .entity_get_spawned_or_despawned_unchecked(self.entity)
                .1
        }
    }

    /// Reborrows this entity in a temporary scope.
    /// This is useful for executing a function that requires a `EntityWorldMut`
    /// but you do not want to move out the entity ownership.
    pub fn reborrow_scope<U>(&mut self, f: impl FnOnce(EntityWorldMut) -> U) -> U {
        let Self {
            entity, location, ..
        } = *self;
        self.world_scope(move |world| {
            f(EntityWorldMut {
                world,
                entity,
                location,
            })
        })
    }

    /// Passes the current entity into the given function, and triggers the [`EntityEvent`] returned by that function.
    /// See [`EntityCommands::trigger`] for usage examples
    ///
    /// [`EntityCommands::trigger`]: crate::system::EntityCommands::trigger
    #[track_caller]
    pub fn trigger<'t, E: EntityEvent<Trigger<'t>: Default>>(
        &mut self,
        event_fn: impl FnOnce(Entity) -> E,
    ) -> &mut Self {
        let mut event = (event_fn)(self.entity);
        let caller = MaybeLocation::caller();
        self.world_scope(|world| {
            world.trigger_ref_with_caller(
                &mut event,
                &mut <E::Trigger<'_> as Default>::default(),
                caller,
            );
        });
        self
    }
}

/// A view into a single entity and component in a world, which may either be vacant or occupied.
///
/// This `enum` can only be constructed from the [`entry`] method on [`EntityWorldMut`].
///