pub type Capability = Box<dyn for<'a> Pass<Parse<'a>>>;Expand description
A capability pass, boxed for Language::pipeline.
A capability is a pass_lang::Pass over a Parse, named by its
Pass::name. Implement the pass for every lifetime —
impl<'a> Pass<Parse<'a>> for MyPass — and box it as a Capability; the
language then runs it whenever its schematic includes that name.
§Examples
use lang_forge::pass_lang::{Outcome, Pass, PassError};
use lang_forge::{Capability, Parse};
struct CountNodes(usize);
impl<'a> Pass<Parse<'a>> for CountNodes {
fn name(&self) -> &'static str {
"count-nodes"
}
fn run(&mut self, parse: &mut Parse<'a>) -> Result<Outcome, PassError> {
self.0 = parse.tree().descendants().count();
Ok(Outcome::Unchanged)
}
}
let capability: Capability = Box::new(CountNodes(0));
assert_eq!(capability.name(), "count-nodes");Aliased Type§
pub struct Capability(/* private fields */);