Function nom::bytes::complete::take[][src]

pub fn take<C, Input, Error: ParseError<Input>>(
    count: C
) -> impl Fn(Input) -> IResult<Input, Input, Error> where
    Input: InputIter + InputTake,
    C: ToUsize

Returns an input slice containing the first N input elements (Input[..N])

It will return Err(Err::Error((_, ErrorKind::Eof))) if the input is shorter than the argument

Example

use nom::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(Err::Error(("short", ErrorKind::Eof))));
assert_eq!(take6(""), Err(Err::Error(("", ErrorKind::Eof))));