pub trait ContextEntitiesExt {
Show 17 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 track_periodic_value_change_counts<E, PL, P, F>(
&mut self,
period: f64,
handler: F,
)
where E: Entity,
PL: PropertyList<E> + Eq + Hash,
P: Property<E> + Eq + Hash,
F: Fn(&mut Context, &mut StratifiedValueChangeCounter<E, PL, P>) + 'static;
fn with_query_results<'a, E: Entity, Q: Query<E>>(
&'a self,
query: Q,
callback: &mut dyn FnMut(EntitySet<'a, 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 count_and_sample_entity<E, Q, R>(
&self,
rng_id: R,
query: Q,
) -> (usize, 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<E: Entity, Q: Query<E>>(&self, query: Q) -> EntitySet<'_, 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 full indexing of property values for the property P.
This method is called with the turbo-fish syntax:
context.index_property::<Person, Age>()
This method both enables the index and catches it up to the current population.
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 track_periodic_value_change_counts<E, PL, P, F>(
&mut self,
period: f64,
handler: F,
)
fn track_periodic_value_change_counts<E, PL, P, F>( &mut self, period: f64, handler: F, )
Tracks periodic value change counts for a newly created counter.
Also panics if period is not finite and strictly positive.
Recording starts at ExecutionPhase::First at simulation start time. The
first report runs at simulation start time in ExecutionPhase::Last, then at
each subsequent start_time + k * period. After the handler returns, the
matched counter is cleared.
context.track_periodic_value_change_counts::<Person, (InfectionStatus,), Age>(
30.0,
|_context, counter| {
let _ = counter;
},
);Sourcefn with_query_results<'a, E: Entity, Q: Query<E>>(
&'a self,
query: Q,
callback: &mut dyn FnMut(EntitySet<'a, E>),
)
fn with_query_results<'a, E: Entity, Q: Query<E>>( &'a self, query: Q, callback: &mut dyn FnMut(EntitySet<'a, E>), )
This method gives client code direct access to the query result as an EntitySet.
This is especially efficient for indexed queries, as this method can reduce to wrapping
a single indexed source.
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 count_and_sample_entity<E, Q, R>(
&self,
rng_id: R,
query: Q,
) -> (usize, Option<EntityId<E>>)
fn count_and_sample_entity<E, Q, R>( &self, rng_id: R, query: Q, ) -> (usize, Option<EntityId<E>>)
Count query results and sample a single entity uniformly from them.
Returns (count, sample), where sample is None iff count == 0.
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<E: Entity, Q: Query<E>>(&self, query: Q) -> EntitySet<'_, E>
fn query<E: Entity, Q: Query<E>>(&self, query: Q) -> EntitySet<'_, E>
Generates an EntitySet representing the query results.
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.