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<'s>(input: &mut &'s str) -> PResult<&'s str, InputError<&'s str>> {
take_while(1.., ('a'..='f', 'A'..='F', '0'..='9')).parse_next(input)
}
assert_eq!(hex_digit1.parse_peek("21cZ"), Ok(("Z", "21c")));
assert_eq!(hex_digit1.parse_peek("H2"), Err(ErrMode::Backtrack(InputError::new("H2", ErrorKind::Slice))));
assert_eq!(hex_digit1.parse_peek(""), Err(ErrMode::Backtrack(InputError::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