ixa::people

Trait ContextPeopleExt

Source
pub trait ContextPeopleExt {
    // 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 + 'static>(
        &self,
        person_id: PersonId,
        _property: T,
    ) -> T::Value;
    fn set_person_property<T: PersonProperty + 'static>(
        &mut self,
        person_id: PersonId,
        _property: T,
        value: T::Value,
    );
    fn index_property<T: PersonProperty + 'static>(&mut self, property: T);
    fn query_people<T: Query>(&self, q: T) -> Vec<PersonId>;
    fn query_people_count<T: Query>(&self, q: T) -> usize;
    fn match_person<T: Query>(&self, person_id: PersonId, q: T) -> bool;
    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, T: Query>(
        &self,
        rng_id: R,
        query: T,
    ) -> Option<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 + 'static>( &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 + 'static>( &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 + 'static>(&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 query_people<T: Query>(&self, q: T) -> Vec<PersonId>

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<T: Query>(&self, q: T) -> 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<T: Query>(&self, person_id: PersonId, q: T) -> bool

Determine whether a person matches a given expression.

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

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, T: Query>( &self, rng_id: R, query: T, ) -> 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().

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§