diff --git a/crates/bevy_ecs/src/entity/map_entities.rs b/crates/bevy_ecs/src/entity/map_entities.rs index 585ec731d8..59949c1603 100644 --- a/crates/bevy_ecs/src/entity/map_entities.rs +++ b/crates/bevy_ecs/src/entity/map_entities.rs @@ -51,6 +51,25 @@ pub trait MapEntities { /// (mapper inputs) to the current world's entities (mapper outputs). /// /// More generally, this can be used to map [`Entity`] references between any two [`Worlds`](World). +/// +/// ## Example +/// +/// ``` +/// # use bevy_ecs::entity::{Entity, EntityMapper}; +/// # use bevy_utils::EntityHashMap; +/// # +/// pub struct SimpleEntityMapper { +/// map: EntityHashMap, +/// } +/// +/// // Example implementation of EntityMapper where we map an entity to another entity if it exists +/// // in the underlying `EntityHashMap`, otherwise we just return the original entity. +/// impl EntityMapper for SimpleEntityMapper { +/// fn map_entity(&mut self, entity: Entity) -> Entity { +/// self.map.get(&entity).copied().unwrap_or(entity) +/// } +/// } +/// ``` pub trait EntityMapper { /// Map an entity to another entity fn map_entity(&mut self, entity: Entity) -> Entity;