Trait ContextPeopleExt

Source
pub trait ContextPeopleExt {
Show 13 methods // Required methods fn get_current_population(&self) -> usize; fn add_person<T: InitializationList>( &mut self, props: T, ) -> Result<PersonId, IxaError>; fn get_person_property<T: PersonProperty>( &self, person_id: PersonId, _property: T, ) -> T::Value; fn set_person_property<T: PersonProperty>( &mut self, person_id: PersonId, _property: T, value: T::Value, ); fn index_property<T: PersonProperty>(&mut self, property: T); fn with_query_results<Q: Query>( &self, query: Q, callback: &mut dyn FnMut(&HashSet<PersonId>), ); fn query_people<Q: Query>(&self, query: Q) -> Vec<PersonId>; fn query_people_count<Q: Query>(&self, query: Q) -> usize; fn match_person<Q: Query>(&self, person_id: PersonId, query: Q) -> bool; fn filter_people<Q: Query>(&self, people: &mut Vec<PersonId>, query: Q); fn tabulate_person_properties<T: Tabulator, F>( &self, tabulator: &T, print_fn: F, ) where F: Fn(&Context, &[String], usize); fn sample_person<R: RngId + 'static, Q: Query>( &self, rng_id: R, query: Q, ) -> Option<PersonId> where R::RngType: Rng; fn sample_people<R: RngId + 'static, Q: Query>( &self, rng_id: R, query: Q, n: usize, ) -> Vec<PersonId> where R::RngType: Rng;
}
Expand description

A trait extension for Context that exposes the people functionality.

Required Methods§

Source

fn get_current_population(&self) -> usize

Returns the current population size

Source

fn add_person<T: InitializationList>( &mut self, props: T, ) -> Result<PersonId, IxaError>

Creates a new person. The caller must supply initial values for all non-derived properties that don’t have a default or an initializer. Note that although this technically takes any type that implements InitializationList it is best to take advantage of the provided syntax that implements InitializationList for tuples, such as: let person = context.add_person((Age, 42)).unwrap();

§Errors

Will return IxaError if a required initializer is not provided.

Source

fn get_person_property<T: PersonProperty>( &self, person_id: PersonId, _property: T, ) -> T::Value

Given a PersonId returns the value of a defined person property, initializing it if it hasn’t been set yet. If no initializer is provided, and the property is not set this will panic, as long as the property has been set or subscribed to at least once before. Otherwise, Ixa doesn’t know about the property.

Source

fn set_person_property<T: PersonProperty>( &mut self, person_id: PersonId, _property: T, value: T::Value, )

Given a PersonId, sets the value of a defined person property Panics if the property is not initialized. Fires a change event.

Source

fn index_property<T: PersonProperty>(&mut self, property: T)

Create an index for property T.

If an index is available Context::query_people() will use it, so this is intended to allow faster querying of commonly used properties. Ixa may choose to create an index for its own reasons even if Context::index_property() is not called, so this function just ensures that one is created.

Source

fn with_query_results<Q: Query>( &self, query: Q, callback: &mut dyn FnMut(&HashSet<PersonId>), )

Query for all people matching a given set of criteria, calling the scope callback with an immutable reference to the fully realized result set.

If you don’t need the entire result set, consider using [Context::query_result_iterator], which gives an iterator that computes the results as needed. If you only need to count the results, use Context::query_people_count

Context::with_query_results() takes any type that implements Query, but instead of implementing query yourself it is best to use the automatic syntax that implements Query for a tuple of pairs of (property, value), like so: context.query_people(((Age, 30), (Gender, Female))).

Source

fn query_people<Q: Query>(&self, query: Q) -> Vec<PersonId>

👎Deprecated since 0.3.4: Use with_query_results, which is much faster for indexed results

Query for all people matching a given set of criteria.

Context::query_people() takes any type that implements Query, but instead of implementing query yourself it is best to use the automatic syntax that implements Query for a tuple of pairs of (property, value), like so: context.query_people(((Age, 30), (Gender, Female))).

Source

fn query_people_count<Q: Query>(&self, query: Q) -> usize

Get the count of all people matching a given set of criteria.

Context::query_people_count() takes any type that implements Query, but instead of implementing query yourself it is best to use the automatic syntax that implements Query for a tuple of pairs of (property, value), like so: context.query_people(((Age, 30), (Gender, Female))).

This is intended to be slightly faster than Context::query_people() because it does not need to allocate a list. We haven’t actually measured it, so the difference may be modest if any.

Source

fn match_person<Q: Query>(&self, person_id: PersonId, query: Q) -> bool

Determine whether a person matches a given expression.

The syntax here is the same as with Context::query_people().

Source

fn filter_people<Q: Query>(&self, people: &mut Vec<PersonId>, query: Q)

Similar to match_person, but more efficient, it removes people from a list who do not match the given query. Note that this method modifies the vector in-place, so it is up to the caller to clone the vector if they don’t want to modify their original vector.

Source

fn tabulate_person_properties<T: Tabulator, F>( &self, tabulator: &T, print_fn: F, )
where F: Fn(&Context, &[String], usize),

Source

fn sample_person<R: RngId + 'static, Q: Query>( &self, rng_id: R, query: Q, ) -> Option<PersonId>
where R::RngType: Rng,

Randomly sample a person from the population of people who match the query. Returns None if no people match the query.

The syntax here is the same as with Context::query_people().

Source

fn sample_people<R: RngId + 'static, Q: Query>( &self, rng_id: R, query: Q, n: usize, ) -> Vec<PersonId>
where R::RngType: Rng,

Randomly sample a list of people from the population of people who match the query. Returns an empty list if no people match the query.

The syntax here is the same as with Context::query_people().

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.

Implementors§