Trait EntityMapper
pub trait EntityMapper {
// Required methods
fn get_mapped(&mut self, source: Entity) -> Entity;
fn set_mapped(&mut self, source: Entity, target: Entity);
}Expand description
An implementor of this trait knows how to map an Entity into another Entity.
Usually this is done by using an [EntityHashMap<Entity>] to map source entities
(mapper inputs) to the current world’s entities (mapper outputs).
More generally, this can be used to map Entity references between any two Worlds.
This is used by [MapEntities] implementers.
§Example
pub struct SimpleEntityMapper {
map: EntityHashMap<Entity>,
}
// 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 get_mapped(&mut self, entity: Entity) -> Entity {
self.map.get(&entity).copied().unwrap_or(entity)
}
fn set_mapped(&mut self, source: Entity, target: Entity) {
self.map.insert(source, target);
}
}Required Methods§
fn get_mapped(&mut self, source: Entity) -> Entity
fn get_mapped(&mut self, source: Entity) -> Entity
Returns the “target” entity that maps to the given source.
fn set_mapped(&mut self, source: Entity, target: Entity)
fn set_mapped(&mut self, source: Entity, target: Entity)
Maps the target entity to the given source. For some implementations this might not actually determine the result
of EntityMapper::get_mapped.
Trait Implementations§
§impl EntityMapper for &mut dyn EntityMapper
impl EntityMapper for &mut dyn EntityMapper
§fn get_mapped(&mut self, source: Entity) -> Entity
fn get_mapped(&mut self, source: Entity) -> Entity
Returns the “target” entity that maps to the given
source.§fn set_mapped(&mut self, source: Entity, target: Entity)
fn set_mapped(&mut self, source: Entity, target: Entity)
Maps the
target entity to the given source. For some implementations this might not actually determine the result
of EntityMapper::get_mapped.