pub fn take<C, I, Error: ParseError<I>>(
count: C
) -> impl Fn(I) -> IResult<I, <I as Stream>::Slice, Error>where
I: Stream,
C: ToUsize,👎Deprecated since 0.1.0: Replaced with <code>winnow::bytes::take</code> with input wrapped in <code>winnow::Partial</code>
Expand description
Returns an input slice containing the first N input elements (I[..N]).
Partial Specific
Partial version if the input has less than N elements, take will
return a ErrMode::Incomplete(Needed::new(M)) where M is the number of
additional bytes the parser would need to succeed.
It is well defined for &[u8] as the number of elements is the byte size,
but for types like &str, we cannot know how many bytes correspond for
the next few chars, so the result will be ErrMode::Incomplete(Needed::Unknown)
Example
use winnow::bytes::streaming::take;
fn take6(s: &str) -> IResult<&str, &str> {
take(6usize)(s)
}
assert_eq!(take6("1234567"), Ok(("7", "123456")));
assert_eq!(take6("things"), Ok(("", "things")));
assert_eq!(take6("short"), Err(ErrMode::Incomplete(Needed::Unknown)));WARNING: Deprecated, replaced with winnow::bytes::take with input wrapped in winnow::Partial