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>
Expand description
Returns an input slice containing the first N input elements (I[..N]).
It will return Err(ErrMode::Backtrack((_, ErrorKind::Eof))) if the input is shorter than the argument.
Example
use winnow::bytes::complete::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::Backtrack(Error::new("short", ErrorKind::Eof))));
assert_eq!(take6(""), Err(ErrMode::Backtrack(Error::new("", ErrorKind::Eof))));The units that are taken will depend on the input type. For example, for a
&str it will take a number of char’s, whereas for a &[u8] it will
take that many u8’s:
use winnow::error::Error;
use winnow::bytes::complete::take;
assert_eq!(take::<_, _, Error<_>>(1usize)("💙"), Ok(("", "💙")));
assert_eq!(take::<_, _, Error<_>>(1usize)("💙".as_bytes()), Ok((b"\x9F\x92\x99".as_ref(), b"\xF0".as_ref())));WARNING: Deprecated, replaced with winnow::bytes::take