Function winnow::bytes::complete::take_while
source · pub fn take_while<T, I, Error: ParseError<I>>(
list: T
) -> impl Fn(I) -> IResult<I, <I as Stream>::Slice, Error>where
I: Stream,
T: ContainsToken<<I as Stream>::Token>,👎Deprecated since 0.1.0: Replaced with <code>winnow::bytes::take_while0</code>
Expand description
Returns the longest input slice (if any) that matches the predicate.
The parser will return the longest slice that matches the given predicate (a function that takes the input and returns a bool).
Example
use winnow::bytes::complete::take_while;
use winnow::stream::AsChar;
fn alpha(s: &[u8]) -> IResult<&[u8], &[u8]> {
take_while(AsChar::is_alpha)(s)
}
assert_eq!(alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
assert_eq!(alpha(b"12345"), Ok((&b"12345"[..], &b""[..])));
assert_eq!(alpha(b"latin"), Ok((&b""[..], &b"latin"[..])));
assert_eq!(alpha(b""), Ok((&b""[..], &b""[..])));WARNING: Deprecated, replaced with winnow::bytes::take_while0