#[replicate]
Expand description
Generate repetitive syntax like trait impls without giving up on
rustfmt
or rust-analyzer.
The last macro expression must be an unterminated block like for
or
while
.
See this crate’s root for a basic language documentation.
§Example
use metamatch::replicate;
#[derive(PartialEq, Eq, PartialOrd, Ord)]
struct NodeIdx(usize);
#[replicate(
let traits = [Add, Sub, Mul, Div, Rem];
for (TRAIT, FUNC) in zip(traits, traits.map(lowercase))
)]
impl core::ops::TRAIT for NodeIdx {
type Output = Self;
fn FUNC(self, rhs: Self) -> Self {
NodeIdx(self.0.FUNC(rhs.0))
}
}
assert!(NodeIdx(1) + NodeIdx(2) == NodeIdx(3));