Trait winnow::stream::ContainsToken
source · pub trait ContainsToken<T> {
// Required method
fn contains_token(&self, token: T) -> bool;
}
Expand description
Check if a token in in a set of possible tokens
This is generally implemented on patterns that a token may match and supports u8
and char
tokens along with the following patterns
b'c'
and'c'
b""
and""
|c| true
b'a'..=b'z'
,'a'..='z'
(etc for each range type)(pattern1, pattern2, ...)
Example
For example, you could implement hex_digit0
as:
fn hex_digit1(input: &str) -> IResult<&str, &str> {
take_while1(('a'..='f', 'A'..='F', '0'..='9')).parse_next(input)
}
assert_eq!(hex_digit1("21cZ"), Ok(("Z", "21c")));
assert_eq!(hex_digit1("H2"), Err(ErrMode::Backtrack(Error::new("H2", ErrorKind::Slice))));
assert_eq!(hex_digit1(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Slice))));
Required Methods§
sourcefn contains_token(&self, token: T) -> bool
fn contains_token(&self, token: T) -> bool
Returns true if self contains the token