Skip to main content

define_derived_property

Macro define_derived_property 

Source
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,
        impl_eq_hash = $impl_eq_hash:ident
        $(, $($extra:tt)+)*
    ) => { ... };
    (
        struct $name:ident ( $visibility:vis Option<$inner_ty:ty> ),
        $entity:ident,
        [$($dependency:ident),*]
        $(, [$($global_dependency:ident),*])?,
        |$($param:ident),+| $derive_fn:expr
        $(, $($extra:tt)+)*
    ) => { ... };
    (
        struct $name:ident ( $($visibility:vis $field_ty:ty),* $(,)? ),
        $entity:ident,
        [$($dependency:ident),*]
        $(, [$($global_dependency:ident),*])?,
        |$($param:ident),+| $derive_fn:expr,
        impl_eq_hash = $impl_eq_hash:ident
        $(, $($extra:tt)+)*
    ) => { ... };
    (
        struct $name:ident ( $($visibility:vis $field_ty:ty),* $(,)? ),
        $entity:ident,
        [$($dependency:ident),*]
        $(, [$($global_dependency:ident),*])?,
        |$($param:ident),+| $derive_fn:expr
        $(, $($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,
        impl_eq_hash = $impl_eq_hash:ident
        $(, $($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
        $(, $($extra:tt)+)*
    ) => { ... };
    (
        enum $name:ident {
            $($variant:ident),* $(,)?
        },
        $entity:ident,
        [$($dependency:ident),*]
        $(, [$($global_dependency:ident),*])?,
        |$($param:ident),+| $derive_fn:expr,
        impl_eq_hash = $impl_eq_hash:ident
        $(, $($extra:tt)+)*
    ) => { ... };
    (
        enum $name:ident {
            $($variant:ident),* $(,)?
        },
        $entity:ident,
        [$($dependency:ident),*]
        $(, [$($global_dependency:ident),*])?,
        |$($param:ident),+| $derive_fn:expr
        $(, $($extra:tt)+)*
    ) => { ... };
}
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!, plus impl_eq_hash = Eq | Hash | both | neither to control whether Eq/Hash are derived or generated for the declared type, mirroring define_property!.