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§
Sourcetype CanonicalValue: PersonPropertyValue
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§
fn compute(context: &Context, person_id: PersonId) -> Self::Value
Sourcefn make_canonical(value: Self::Value) -> Self::CanonicalValue
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.
Sourcefn make_uncanonical(value: Self::CanonicalValue) -> Self::Value
fn make_uncanonical(value: Self::CanonicalValue) -> Self::Value
The inverse transform of make_canonical
. For simple properties, this is the identity function.
fn get_instance() -> Self
fn name() -> &'static str
Sourcefn get_display(value: &Self::CanonicalValue) -> String
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§
fn is_derived() -> bool
fn is_required() -> bool
fn dependencies() -> Vec<Box<dyn PersonPropertyHolder>>
fn register_dependencies(_: &Context)
Sourcefn hash_property_value(value: &Self::CanonicalValue) -> u128
fn hash_property_value(value: &Self::CanonicalValue) -> u128
For cases when the property’s hash needs to be computed in a special way.
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.