pub struct Rule<K> {
pub pattern: Vec<Pattern<K>>,
pub template: Vec<Template<K>>,
}Expand description
One arm of a macro: a pattern to match and the template it expands to.
A rule is plain data. Macro::new validates it and compiles it into the
form the Expander runs.
§Examples
($x:tt) => { $x $x } — duplicate a single tree:
use macro_lang::{Fragment, Pattern, Rule, Template};
use intern_lang::Interner;
let mut names = Interner::new();
let x = names.intern("x");
let rule: Rule<char> = Rule {
pattern: vec![Pattern::Bind { name: x, fragment: Fragment::Tree }],
template: vec![Template::Var(x), Template::Var(x)],
};
assert_eq!(rule.template.len(), 2);Fields§
§pattern: Vec<Pattern<K>>What an invocation must look like for this rule to apply. It must match the invocation’s trees in full.
template: Vec<Template<K>>What the invocation expands to when the pattern matches.
Trait Implementations§
Auto Trait Implementations§
impl<K> Forget for Rule<K>
impl<K> Freeze for Rule<K>
impl<K> Move for Rule<K>
impl<K> RefUnwindSafe for Rule<K>
impl<K> Send for Rule<K>
impl<K> Sync for Rule<K>
impl<K> Unpin for Rule<K>
impl<K> UnsafeUnpin for Rule<K>
impl<K> UnwindSafe for Rule<K>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more