Trait ContainsToken

trait ContainsToken<T>

Check if a token is in a set of possible tokens

While this can be implemented manually, you can also build up sets using:

Example

For example, you could implement hex_digit0 as:

# use winnow::prelude::*;
# use winnow::{error::ErrMode, error::ContextError};
# use winnow::token::take_while;
fn hex_digit1<'s>(input: &mut &'s str) -> ModalResult<&'s str, ContextError> {
    take_while(1.., ('a'..='f', 'A'..='F', '0'..='9')).parse_next(input)
}

assert_eq!(hex_digit1.parse_peek("21cZ"), Ok(("Z", "21c")));
assert!(hex_digit1.parse_peek("H2").is_err());
assert!(hex_digit1.parse_peek("").is_err());

Required Methods

fn contains_token(self: &Self, token: T) -> bool

Returns true if self contains the token

Implementors