macro_rules! define_derived_property {
(
struct $name:ident ( $visibility:vis Option<$inner_ty:ty> ),
$entity:ident,
[$($dependency:ident),*]
$(, [$($global_dependency:ident),*])?,
|$($param:ident),+| $derive_fn:expr
// For `canonical_value` implementations:
$(, $($extra:tt)+),*
) => { ... };
(
struct $name:ident ( $($visibility:vis $field_ty:ty),* $(,)? ),
$entity:ident,
[$($dependency:ident),*]
$(, [$($global_dependency:ident),*])?,
|$($param:ident),+| $derive_fn:expr
// For `canonical_value` implementations:
$(, $($extra:tt)+),*
) => { ... };
(
struct $name:ident { $($visibility:vis $field_name:ident : $field_ty:ty),* $(,)? },
$entity:ident,
[$($dependency:ident),*]
$(, [$($global_dependency:ident),*])?,
|$($param:ident),+| $derive_fn:expr
// For `canonical_value` implementations:
$(, $($extra:tt)+),*
) => { ... };
(
enum $name:ident {
$($variant:ident),* $(,)?
},
$entity:ident,
[$($dependency:ident),*]
$(, [$($global_dependency:ident),*])?,
|$($param:ident),+| $derive_fn:expr
// For `canonical_value` implementations:
$(, $($extra:tt)+),*
) => { ... };
(
@construct_compute_fn
$entity:ident,
[$($dependency:ident),*],
[$($global_dependency:ident),*],
|$($param:ident),+| $derive_fn:expr
) => { ... };
}Expand description
The “derived” variant of define_property! for defining simple derived property types.
Defines a struct or enum with a standard set of derives and automatically invokes
impl_derived_property! for it.
Defines a derived property with the following parameters:
- Property type declaration: A struct or enum declaration.
$entity: The name of the entity of which the new type is a property.[$($dependency),+]: A list of person properties the derived property depends on.[$(global_dependency),*]: A list of global properties the derived property depends on. Can optionally be omitted if empty.$calculate: A closure that takes the values of each dependency and returns the derived value.- Optional parameters: The same optional parameters accepted by
impl_property!.