Function rocket::mtls::x509::der_parser::asn1_rs::nom::bytes::complete::take_till

source ·
pub fn take_till<F, Input, Error>(cond: F) -> impl Fn(Input)
where Error: ParseError<Input>, Input: InputTakeAtPosition, F: Fn(<Input as InputTakeAtPosition>::Item) -> bool,
Available on crate feature mtls only.
Expand description

Returns the longest input slice (if any) till a predicate is met.

The parser will return the longest slice till the given predicate (a function that takes the input and returns a bool).

§Example

use nom::bytes::complete::take_till;

fn till_colon(s: &str) -> IResult<&str, &str> {
  take_till(|c| c == ':')(s)
}

assert_eq!(till_colon("latin:123"), Ok((":123", "latin")));
assert_eq!(till_colon(":empty matched"), Ok((":empty matched", ""))); //allowed
assert_eq!(till_colon("12345"), Ok(("", "12345")));
assert_eq!(till_colon(""), Ok(("", "")));