macro_rules! declare_family {
(
$(#[$meta:meta])*
root: $vis:vis $Root:ident,
child: [
$(
$(#[$child_meta:meta])*
$Child:ident
),+ $(,)?
]
) => { ... };
(
$(#[$meta:meta])*
root: mut $vis:vis $Root:ident,
child: [
$(
$(#[$child_meta:meta])*
$Child:ident
),+ $(,)?
]
) => { ... };
}Expand description
Declares a plugin model family using marker types.
This macro generates a family root trait and one or more child markers used to represent operations within that family.
The generated markers are purely type-level and contain no runtime data.
Concrete plugin implementations attach to a (Root, Child) pair via
plugin_model!, allowing models to be selected later through context
and trait bounds.
§Parameters
root: Declares the family root trait.- Can include a visibility modifier (
pub,pub(crate), etc.). - The same visibility is applied to all child marker structs.
- Prefix with
mutto create a mutable plugin family.
- Can include a visibility modifier (
child: A list of child marker types representing operations within the family.
§Syntax
declare_family! {
root: pub FamilyRoot,
child: [OperationA, OperationB, OperationC]
}Mutable families use the mut keyword:
declare_family! {
root: mut pub FamilyRoot,
child: [OperationA, OperationB]
}§Generated Types
The macro generates:
- A child marker struct for each entry in
child. - A family root trait defining associated plugin model types for each child operation.
The child marker structs are zero-sized types used purely as identifiers for operations within the family.
The root trait declares an associated model type per child:
- Immutable families require models implementing
PurePluginModel. - Mutable families require models implementing
MutablePluginModel.
Each associated type corresponds to a concrete plugin implementation bound to that operation.
These associated model types are later used by plugin_model! to bind
concrete implementations to specific (Root, Child) combinations.
§Example
declare_family! {
root: pub VotingFamily,
child: [Phragmen, STV]
}Expands roughly to:
pub struct Phragmen;
pub struct STV;
pub trait VotingFamily<Input, Context, Output> {
type Phragmen: PurePluginModel<Input, Context, Output>;
type STV: PurePluginModel<Input, Context, Output>;
}Mutable family example:
declare_family! {
root: mut pub StorageFamily,
child: [Insert, Remove]
}Expands roughly to:
pub struct Insert;
pub struct Remove;
pub trait StorageFamily<Input, Context, Output> {
type Insert: MutablePluginModel<Input, Context, Output>;
type Remove: MutablePluginModel<Input, Context, Output>;
}