Macro iter_char_context

Source
macro_rules! iter_char_context {
    ($iter:expr) => { ... };
}
Expand description

Take a dyn Iterator<Item = &char> and return a closure that calls .iter() and maps the values onto [winnow::error::StrContextValue::CharLiteral].

ยงExample

use alpm_parsers::iter_char_context;
use winnow::{ModalResult, Parser, combinator::cut_err, token::one_of};

fn parser(input: &mut &str) -> ModalResult<char> {
    let accepted_characters = ['a', 'b', 'c'];
    cut_err(one_of(accepted_characters))
        .context_with(iter_char_context!(accepted_characters))
        .parse_next(input)
}

assert!(parser.parse("a").is_ok());