Skip to main content

Rule

Struct Rule 

Source
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§

Source§

impl<K: Clone> Clone for Rule<K>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K: Debug> Debug for Rule<K>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K> Forget for Rule<K>

§

impl<K> Freeze for Rule<K>
where Vec<Pattern<K>>: Freeze, Vec<Template<K>>: Freeze,

§

impl<K> Move for Rule<K>

§

impl<K> RefUnwindSafe for Rule<K>

§

impl<K> Send for Rule<K>
where Vec<Pattern<K>>: Send, Vec<Template<K>>: Send,

§

impl<K> Sync for Rule<K>
where Vec<Pattern<K>>: Sync, Vec<Template<K>>: Sync,

§

impl<K> Unpin for Rule<K>
where Vec<Pattern<K>>: Unpin, Vec<Template<K>>: Unpin,

§

impl<K> UnsafeUnpin for Rule<K>

§

impl<K> UnwindSafe for Rule<K>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.