use crate::people::HashValueType;
use crate::{Context, ContextPeopleExt, PersonId, PersonProperty};
type PersonCallback<T> = dyn Fn(&Context, PersonId) -> T;
pub(crate) struct Methods {
pub(super) indexer: Box<PersonCallback<HashValueType>>,
pub(super) get_display: Box<PersonCallback<String>>,
}
impl Methods {
pub(super) fn new<T: PersonProperty>() -> Self {
Self {
indexer: Box::new(move |context: &Context, person_id: PersonId| {
let value = context.get_person_property(person_id, T::get_instance());
T::hash_property_value(&T::make_canonical(value))
}),
get_display: Box::new(move |context: &Context, person_id: PersonId| {
let value = context.get_person_property(person_id, T::get_instance());
T::get_display(&T::make_canonical(value))
}),
}
}
}