Function winnow::bytes::streaming::take_while1
source · pub fn take_while1<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_while1</code> with input wrapped in <code>winnow::Partial</code>
Expand description
Returns the longest (at least 1) input slice 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).
It will return an Err(ErrMode::Backtrack((_, ErrorKind::TakeWhile1))) if the pattern wasn’t met.
Partial Specific
Partial version will return a ErrMode::Incomplete(Needed::new(1)) or if the pattern reaches the end of the input.
Example
use winnow::bytes::streaming::take_while1;
use winnow::stream::AsChar;
fn alpha(s: &[u8]) -> IResult<&[u8], &[u8]> {
take_while1(AsChar::is_alpha)(s)
}
assert_eq!(alpha(b"latin123"), Ok((&b"123"[..], &b"latin"[..])));
assert_eq!(alpha(b"latin"), Err(ErrMode::Incomplete(Needed::new(1))));
assert_eq!(alpha(b"12345"), Err(ErrMode::Backtrack(Error::new(&b"12345"[..], ErrorKind::TakeWhile1))));WARNING: Deprecated, replaced with winnow::bytes::take_while1 with input wrapped in winnow::Partial