pub trait ContextEntitiesExt {
Show 14 methods
// Required methods
fn add_entity<E: Entity, PL: PropertyList<E>>(
&mut self,
property_list: PL,
) -> Result<EntityId<E>, IxaError>;
fn get_property<E: Entity, P: Property<E>>(
&self,
entity_id: EntityId<E>,
) -> P;
fn set_property<E: Entity, P: Property<E>>(
&mut self,
entity_id: EntityId<E>,
property_value: P,
);
fn index_property<E: Entity, P: Property<E>>(&mut self);
fn index_property_counts<E: Entity, P: Property<E>>(&mut self);
fn with_query_results<E: Entity, Q: Query<E>>(
&self,
query: Q,
callback: &mut dyn FnMut(&IndexSet<EntityId<E>>),
);
fn query_entity_count<E: Entity, Q: Query<E>>(&self, query: Q) -> usize;
fn sample_entity<E, Q, R>(&self, rng_id: R, query: Q) -> Option<EntityId<E>>
where E: Entity,
Q: Query<E>,
R: RngId + 'static,
R::RngType: Rng;
fn sample_entities<E, Q, R>(
&self,
rng_id: R,
query: Q,
n: usize,
) -> Vec<EntityId<E>>
where E: Entity,
Q: Query<E>,
R: RngId + 'static,
R::RngType: Rng;
fn get_entity_count<E: Entity>(&self) -> usize;
fn get_entity_iterator<E: Entity>(&self) -> PopulationIterator<E> ⓘ;
fn query_result_iterator<E: Entity, Q: Query<E>>(
&self,
query: Q,
) -> EntitySetIterator<'_, E> ⓘ;
fn match_entity<E: Entity, Q: Query<E>>(
&self,
entity_id: EntityId<E>,
query: Q,
) -> bool;
fn filter_entities<E: Entity, Q: Query<E>>(
&self,
entities: &mut Vec<EntityId<E>>,
query: Q,
);
}Expand description
A trait extension for Context that exposes entity-related
functionality.
Required Methods§
fn add_entity<E: Entity, PL: PropertyList<E>>( &mut self, property_list: PL, ) -> Result<EntityId<E>, IxaError>
Sourcefn get_property<E: Entity, P: Property<E>>(&self, entity_id: EntityId<E>) -> P
fn get_property<E: Entity, P: Property<E>>(&self, entity_id: EntityId<E>) -> P
Fetches the property value set for the given entity_id.
The easiest way to call this method is by assigning it to a variable with an explicit type:
let vaccine_status: VaccineStatus = context.get_property(entity_id);Sourcefn set_property<E: Entity, P: Property<E>>(
&mut self,
entity_id: EntityId<E>,
property_value: P,
)
fn set_property<E: Entity, P: Property<E>>( &mut self, entity_id: EntityId<E>, property_value: P, )
Sets the value of the given property. This method unconditionally emits a PropertyChangeEvent.
Sourcefn index_property<E: Entity, P: Property<E>>(&mut self)
fn index_property<E: Entity, P: Property<E>>(&mut self)
Enables indexing of property values for the property P.
This method is called with the turbo-fish syntax:
context.index_property::<Person, Age>()
The actual computation of the index is done lazily as needed upon execution of queries,
not when this method is called.
Sourcefn index_property_counts<E: Entity, P: Property<E>>(&mut self)
fn index_property_counts<E: Entity, P: Property<E>>(&mut self)
Enables value-count indexing of property values for the property P.
If the property already has a full index, that index is left unchanged, as it already supports value-count queries.
Sourcefn with_query_results<E: Entity, Q: Query<E>>(
&self,
query: Q,
callback: &mut dyn FnMut(&IndexSet<EntityId<E>>),
)
fn with_query_results<E: Entity, Q: Query<E>>( &self, query: Q, callback: &mut dyn FnMut(&IndexSet<EntityId<E>>), )
This method gives client code direct immutable access to the fully realized set of entity IDs. This is especially efficient for indexed queries, as this method reduces to a simple lookup of a hash bucket. Otherwise, the set is allocated and computed.
Sourcefn query_entity_count<E: Entity, Q: Query<E>>(&self, query: Q) -> usize
fn query_entity_count<E: Entity, Q: Query<E>>(&self, query: Q) -> usize
Gives the count of distinct entity IDs satisfying the query. This is especially efficient for indexed queries.
Supplying an empty query () is equivalent to calling get_entity_count::<E>().
Sourcefn sample_entity<E, Q, R>(&self, rng_id: R, query: Q) -> Option<EntityId<E>>
fn sample_entity<E, Q, R>(&self, rng_id: R, query: Q) -> Option<EntityId<E>>
Sample a single entity uniformly from the query results. Returns None if the
query’s result set is empty.
To sample from the entire population, pass in the empty query ().
Sourcefn sample_entities<E, Q, R>(
&self,
rng_id: R,
query: Q,
n: usize,
) -> Vec<EntityId<E>>
fn sample_entities<E, Q, R>( &self, rng_id: R, query: Q, n: usize, ) -> Vec<EntityId<E>>
Sample up to requested entities uniformly from the query results. If the
query’s result set has fewer than requested entities, the entire result
set is returned.
To sample from the entire population, pass in the empty query ().
Sourcefn get_entity_count<E: Entity>(&self) -> usize
fn get_entity_count<E: Entity>(&self) -> usize
Returns a total count of all created entities of type E.
Sourcefn get_entity_iterator<E: Entity>(&self) -> PopulationIterator<E> ⓘ
fn get_entity_iterator<E: Entity>(&self) -> PopulationIterator<E> ⓘ
Returns an iterator over all created entities of type E.
Sourcefn query_result_iterator<E: Entity, Q: Query<E>>(
&self,
query: Q,
) -> EntitySetIterator<'_, E> ⓘ
fn query_result_iterator<E: Entity, Q: Query<E>>( &self, query: Q, ) -> EntitySetIterator<'_, E> ⓘ
Generates an iterator over the results of the query.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.