Trait specs::saveload::MarkerAllocator
source · [−]pub trait MarkerAllocator<M: Marker>: Resource {
fn allocate(&mut self, entity: Entity, id: Option<M::Identifier>) -> M;
fn retrieve_entity_internal(&self, id: M::Identifier) -> Option<Entity>;
fn maintain(&mut self, _entities: &EntitiesRes, _storage: &ReadStorage<'_, M>);
fn retrieve_entity(
&mut self,
marker: M,
storage: &mut WriteStorage<'_, M>,
entities: &EntitiesRes
) -> Entity { ... }
fn mark<'m>(
&mut self,
entity: Entity,
storage: &'m mut WriteStorage<'_, M>
) -> Option<(&'m M, bool)> { ... }
}
Expand description
This allocator is used with the Marker
trait.
It provides a method for allocating new Marker
s.
It should also provide a Marker -> Entity
mapping.
The maintain
method can be implemented for cleanup and actualization.
See docs for Marker
for an example.
Required Methods
fn allocate(&mut self, entity: Entity, id: Option<M::Identifier>) -> M
fn allocate(&mut self, entity: Entity, id: Option<M::Identifier>) -> M
Allocates a new marker for a given entity. If you don’t pass an id, a new unique id will be created.
fn retrieve_entity_internal(&self, id: M::Identifier) -> Option<Entity>
fn retrieve_entity_internal(&self, id: M::Identifier) -> Option<Entity>
Get an Entity
by a marker identifier.
This function only accepts an id; it does not update the marker data.
Implementors usually maintain a marker -> entity mapping and use that to retrieve the entity.
fn maintain(&mut self, _entities: &EntitiesRes, _storage: &ReadStorage<'_, M>)
fn maintain(&mut self, _entities: &EntitiesRes, _storage: &ReadStorage<'_, M>)
Maintain internal data. Cleanup if necessary.
Provided Methods
fn retrieve_entity(
&mut self,
marker: M,
storage: &mut WriteStorage<'_, M>,
entities: &EntitiesRes
) -> Entity
fn retrieve_entity(
&mut self,
marker: M,
storage: &mut WriteStorage<'_, M>,
entities: &EntitiesRes
) -> Entity
Tries to retrieve an entity by the id of the marker;
if no entity has a marker with the same id, a new entity
will be created and marker
will be inserted for it.
In case the entity existed,
this method will update the marker data using Marker::update
.