Function nom8::bytes::streaming::take_while
source · pub fn take_while<T, Input, Error: ParseError<Input>>(
list: T
) -> impl Fn(Input) -> IResult<Input, <Input as IntoOutput>::Output, Error>where
Input: InputTakeAtPosition + IntoOutput,
T: FindToken<<Input as InputTakeAtPosition>::Item>,
👎Deprecated since 8.0.0: Replaced with
nom8::bytes::take_while
with input wrapped in nom8::input::Streaming
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).
Streaming Specific
Streaming version will return a Err::Incomplete(Needed::new(1))
if the pattern reaches the end of the input.
Example
use nom8::bytes::streaming::take_while;
use nom8::input::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"), Err(Err::Incomplete(Needed::new(1))));
assert_eq!(alpha(b""), Err(Err::Incomplete(Needed::new(1))));
WARNING: Deprecated, replaced with nom8::bytes::take_while
with input wrapped in nom8::input::Streaming