I'm having issues dealing with lifetimes in a function that takes a function as an argument.
The function that gets passed into my function comes from the Nom parser combinator library.
enum ParserError<'a> {
FailedParse(&'a str),
}
type ParseResult<'a, T> = Result<T, ParserError<'a>>;
fn parse<'a, T, NomParser>(input: &'a str, parser: NomParser) -> ParseResult<'a, T> where NomParser: Fn(&[u8]) -> IResult<&[u8], T> {
unimplemented!()
}
I get the following error:
src/lib.rs:105:18: 105:23 error: type mismatch resolving `for<'r> <fn(&[u8]) -> nom::internal::IResult<&[u8], Expression<'_>> {parser} as core::ops::FnOnce<(&'r [u8],)>>::Output == nom::internal::IResult<&'r [u8], _>`:
expected bound lifetime parameter ,
found concrete lifetime [E0271]
src/lib.rs:105 let actual = parse(input, parser);
^~~~~
src/lib.rs:105:18: 105:23 help: run `rustc --explain E0271` to see a detailed explanation
src/lib.rs:105:18: 105:23 note: required by `parse`
It seems to be because T
in this particular invocation of parse
has an associated lifetime (i.e. T
is Expression<'a>
in this case).
I'm not quite sure how to solve this issue. Any help would be greatly appreciated.