Skip to main content

pass_fn

Function pass_fn 

Source
pub fn pass_fn<C, F>(f: F) -> PassFn<C, F>
where F: for<'a> Fn(&'a str, Span, &'a C) -> Outcome<C> + Send + Sync,
Expand description

Creates a pass from a closure — no struct, no impl block.

The closure receives the same arguments as Pass::parse and returns the same Outcome; captures are allowed, which makes stateful passes (counters, lookup tables) trivial. Passes built this way are named "PassFn" in diagnostics.

§Examples

use increparse::{pass_fn, Outcome, Pass, Span};

let accept = pass_fn(|_source: &str, _span, _ctx: &()| Outcome::Done);
assert!(matches!(accept.parse("abc", Span::new(0, 3, 0), &()), Outcome::Done));