tag_no_case
returns a impl Fn(Input) -> IResult<Input, Input, Error>
which means we have to return something similar from our wrapper function.
For simplicity and brevity let's skip all the generics and just use &str
, at which point the compiler will complain that the returned type is "not general enough" because it isn't generic over lifetimes. We can pin it down to a single lifetime by adding a lifetime parameter to the function signature and using that parameter to annotate the return type.
Final complete working and compiling example:
// nom = "6.1.0"
use nom::{IResult, bytes::complete::tag_no_case, sequence::preceded};
fn schema_parser<'a>() -> impl Fn(&'a str) -> IResult<&'a str, &'a str> {
tag_no_case("schema")
}
fn main() {
let string = String::from("exampleschema");
let mut parser = preceded(tag_no_case("example"), schema_parser());
assert_eq!(parser(&string), Ok(("", "schema"))); // non-'static str
assert_eq!(parser("exampleschema"), Ok(("", "schema"))); // 'static str
}