[][src]Trait legion::world::EntityReplacePolicy

pub trait EntityReplacePolicy<'s> {
    fn src_entities<'a>(&'s self) -> Box<dyn Iterator<Item = Entity> + 'a>
    where
        's: 'a
;
fn dst_entities<'a>(&'s self) -> Box<dyn Iterator<Item = Entity> + 'a>
    where
        's: 'a
;
fn get_dst_entity(&self, src_entity: Entity) -> Option<Entity>; }

Used along with CloneImpl, allows specifying that certain entities in the receiving world should be replaced with entities from the source world.

A typical implementation of this trait would be to wrap a HashMap. src_entities would be implemented by returning keys(), dst_entities would be implemented by returning values(), and get_dst_entity would be implemented by returning the result of get(src_entity).

Default implementations provided in legion include:

  • NoneEntityReplacePolicy - No entity replacement will occur
  • HashMapCloneImplResult - Wraps the standard library's HashMap.

Required methods

fn src_entities<'a>(&'s self) -> Box<dyn Iterator<Item = Entity> + 'a> where
    's: 'a, 

Returns all entities in the source world that will replace data in the destination world

Safety

  • All entities returned via the iterator must exist in the source world
  • All entities that will be copied from the source world must be included in the returned iterator.

fn dst_entities<'a>(&'s self) -> Box<dyn Iterator<Item = Entity> + 'a> where
    's: 'a, 

Returns all entities in the destination world that will be replaced

Safety

  • All entities returned via the iterator must exist in the destination world
  • All entities that will be replaced in the destination world must be included in the returned iterator

fn get_dst_entity(&self, src_entity: Entity) -> Option<Entity>

Returns the entity in the destination world that will be replaced by the given entity in the source world, otherwise None if the entity in the source world should not replace anything.

Safety

  • All entities passed into this function that result in a non-None return value must be included in the iterator returned by src_entities
  • All entities returned by this function must be included in the iterator returned by dst_entities
Loading content...

Implementors

impl<'m, 's> EntityReplacePolicy<'s> for HashMapEntityReplacePolicy<'m>[src]

impl<'s> EntityReplacePolicy<'s> for NoneEntityReplacePolicy[src]

Loading content...