[][src]Function gchemol_parser::parsers::take

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

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))));