Hello,
I'm writing parser utilities on top of nom, so I'm going to have lots of functions that return closures. To decrease verbosity and enforce consistency, I tried to create some type aliases like so:
use nom::IResult;
use nom_locate::LocatedSpan;
use crate::parse::error::PError;
pub type Span<'a> = LocatedSpan<&'a str>;
pub type PResult<'a, T> = IResult<Span<'a>, T, PError>;
pub type Parser<'a, T> = impl Fn(Span<'a>) -> PResult<'a, T>;
However, the last line is illegal:
error[E0658]: `impl Trait` in type aliases is unstable
--> src/parse.rs:9:26
|
9 | pub type Parser<'a, T> = impl Fn(Span<'a>) -> PResult<'a, T>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
error: unconstrained opaque type
--> src/parse.rs:9:26
|
9 | pub type Parser<'a, T> = impl Fn(Span<'a>) -> PResult<'a, T>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `Parser` must be used in combination with a concrete type within the same module
For more information about this error, try `rustc --explain E0658`.
And no, I don't want to use unstable or pack everything into one module. Is there any other way to simplify function definitions that return closures? Thanks!
Best, Oliver