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

Code before:
///
/// # Panics
///
/// The command will panic when applied if the target entity does not exist.
///
/// [`Ignore`]: crate::component::ComponentCloneBehavior::Ignore
/// [`Custom`]: crate::component::ComponentCloneBehavior::Custom
pub fn move_components<B: Bundle>(target: Entity) -> impl EntityCommand {
    move |mut entity: EntityWorldMut| {
        entity.move_components::<B>(target);
    }
}

/// An [`EntityCommand`] that logs the components of an entity.
pub fn log_components() -> impl EntityCommand {
    move |entity: EntityWorldMut| {
        let name = entity
            .get::<Name>()
            .map(|name| format!(" ({name})"))
            .unwrap_or_default();
        let id = entity.id();
        let debug_infos: Vec<_> = entity
            .world()
            .inspect_entity(entity.id())
            .expect("Entity existence is verified before an EntityCommand is executed")
            .map(|info| info.name().to_string())
            .collect();
        info!("{id}{name}: {debug_infos:?}");
    }
}


Review comment (bug):
just leaving a note here that this isn't as_string because as_string only exists on `debug` whereas `to_string` handles the debug/no-debug difference



Code after:
/// All other components will be moved without any other special handling.
///
/// Note that this will trigger `on_remove` hooks/observers on this entity and `on_insert`/`on_add` hooks/observers on the target entity.
///
/// # Panics
///
/// The command will panic when applied if the target entity does not exist.
///
/// [`Ignore`]: crate::component::ComponentCloneBehavior::Ignore
/// [`Custom`]: crate::component::ComponentCloneBehavior::Custom
pub fn move_components<B: Bundle>(target: Entity) -> impl EntityCommand {
    move |mut entity: EntityWorldMut| {
        entity.move_components::<B>(target);
    }
}

/// An [`EntityCommand`] that logs the components of an entity.
pub fn log_components() -> impl EntityCommand {
    move |entity: EntityWorldMut| {
        let name = entity.get::<Name>().map(ToString::to_string);
        let id = entity.id();
        let mut components: Vec<_> = entity
            .world()
            .inspect_entity(id)
            .expect("Entity existence is verified before an EntityCommand is executed")
            .map(|info| info.name().to_string())
            .collect();
        components.sort();

        #[cfg(not(feature = "debug"))]
        {
            let component_count = components.len();
            #[cfg(feature = "trace")]
            {
                if let Some(name) = name {
                    info!(id=?id, name=?name, ?component_count, "log_components. Enable the `debug` feature to log component names.");
                } else {
                    info!(id=?id, ?component_count, "log_components. Enable the `debug` feature to log component names.");
                }
            }
            #[cfg(not(feature = "trace"))]
            {
                let name = name
                    .map(|name| alloc::format!(" ({name})"))
                    .unwrap_or_default();
                info!("Entity {id}{name}: {component_count} components. Enable the `debug` feature to log component names.");
            }
        }

        #[cfg(feature = "debug")]
        {