Function rocket::mtls::x509::der_parser::asn1_rs::nom::bytes::streaming::take

source ·
pub fn take<C, Input, Error>(count: C) -> impl Fn(Input)
where Error: ParseError<Input>, Input: InputIter + InputTake + InputLength, C: ToUsize,
Available on crate feature mtls only.
Expand description

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

§Streaming Specific

Streaming version if the input has less than N elements, take will return a Err::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 Err::Incomplete(Needed::Unknown)

§Example

use nom::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(Err::Incomplete(Needed::Unknown)));