macro_rules! modifier {
($(<$($name:ident : $bounds:path),+>)? $modifier:ident <$dim:ident>, $trait_name:ident, $doc:expr, $builder_name: ident, $($arg:ident : $ty:ty),*) => { ... };
($dim:ident $(<$($name:ident : $bounds:path),+>)? $modifier:ident, $trait_name:ident, $doc:expr, $builder_name:ident, $($arg:ident : $ty:ty),*) => { ... };
}Expand description
Creates boilerplate (including a builder extension trait) for modifiers
Example:
modifier!(<F: Fn(&Schedule<Ix1>) -> f64> Magicify<Ix1>,
MagicifyBuilder,
r"Apply magic to the schedule",
magicify,
magic_amt: usize,
magic_fn: F
);
impl<F: Fn(&Schedule<Ix1>) -> f64> Modifier<Ix1> for Magicify<F> {
type Output<T: Generator<Ix1>> = MagicifyGenerator<T, F>;
fn modify<T: Generator<Ix1>>(self, generator: T) -> Self::Output<T> {
// ...
}
}- The parameter in angle brackets is an optional list generic parameters with bounds
- The second parameter is the name of the modifier. The macro will create a tuple-struct with that name and all the parameters.
- The third supplies documentation to the modifier and to the builder method.
- The fourth is the name of the builder trait that will be automatically implemented on all generators
- The fifth is the name of the builder method that will be able to be called on generators (for example
.tm_filter()). - The rest are arguments to be passed into the modifier’s
newfunction, the builder method, and added as fields to the modifier.