From b17d42dbe9ba15de9c22dccc90847d7355a80712 Mon Sep 17 00:00:00 2001 From: Charles Bournhonesque Date: Mon, 29 Jan 2024 11:56:44 -0500 Subject: [PATCH] Add a doctest example for EntityMapper (#11583) # Objective Fixes: https://github.com/bevyengine/bevy/issues/11549 Add a doctest example of what a custom implementation of an `EntityMapper` would look like. (need to wait until https://github.com/bevyengine/bevy/pull/11428 is merged) --------- Co-authored-by: Charles Bournhonesque Co-authored-by: Alice Cecile Co-authored-by: Hennadii Chernyshchyk --- crates/bevy_ecs/src/entity/map_entities.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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;