Trait PersonProperty

Source
pub trait PersonProperty: Copy + 'static {
    type Value: PersonPropertyValue;
    type CanonicalValue: PersonPropertyValue;

    // Required methods
    fn compute(context: &Context, person_id: PersonId) -> Self::Value;
    fn make_canonical(value: Self::Value) -> Self::CanonicalValue;
    fn make_uncanonical(value: Self::CanonicalValue) -> Self::Value;
    fn get_instance() -> Self;
    fn name() -> &'static str;
    fn get_display(value: &Self::CanonicalValue) -> String;

    // Provided methods
    fn is_derived() -> bool { ... }
    fn is_required() -> bool { ... }
    fn dependencies() -> Vec<Box<dyn PersonPropertyHolder>> { ... }
    fn register_dependencies(_: &Context) { ... }
    fn hash_property_value(value: &Self::CanonicalValue) -> u128 { ... }
    fn type_id() -> TypeId { ... }
}
Expand description

An individual characteristic or state related to a person, such as age or disease status.

Person properties should be defined with the define_person_property!(), define_person_property_with_default!() and define_derived_property!() macros.

Required Associated Types§

Source

type Value: PersonPropertyValue

The type of the property’s values.

Source

type CanonicalValue: PersonPropertyValue

Some properties might store a transformed version of the value in the index. This is the type of the transformed value. For simple properties this will be the same as Self::Value.

Required Methods§

Source

fn compute(context: &Context, person_id: PersonId) -> Self::Value

Source

fn make_canonical(value: Self::Value) -> Self::CanonicalValue

This transforms a Self::Value into a Self::CanonicalValue, e.g. for storage in an index. For simple properties, this is the identity function.

Source

fn make_uncanonical(value: Self::CanonicalValue) -> Self::Value

The inverse transform of make_canonical. For simple properties, this is the identity function.

Source

fn get_instance() -> Self

Source

fn name() -> &'static str

Source

fn get_display(value: &Self::CanonicalValue) -> String

Returns a string representation of the property value, e.g. for writing to a CSV file. If make_uncanonical is nontrivial, this method usually transforms value into a Self::Value first so that the value is formatted in a way the user expects.

Provided Methods§

Source

fn is_derived() -> bool

Source

fn is_required() -> bool

Source

fn dependencies() -> Vec<Box<dyn PersonPropertyHolder>>

Source

fn register_dependencies(_: &Context)

Source

fn hash_property_value(value: &Self::CanonicalValue) -> u128

For cases when the property’s hash needs to be computed in a special way.

Source

fn type_id() -> TypeId

Overridden by multi-properties, which use the TypeId of the ordered tuple so that tuples with the same component types in a different order will have the same type ID.

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§