quick-error icon indicating copy to clipboard operation
quick-error copied to clipboard

Generic type arguments on errors.

Open canndrew opened this issue 9 years ago • 7 comments

I just discovered that this isn't possible:

quick_error! {
    pub enum MyFancyError<E> {
        Foo(e: E) { }
    }
}

Which is a shame, because this would be very useful.

canndrew avatar Feb 26 '16 08:02 canndrew

The error I'm wrapping has a lifetime parameter, so I would need this as well.

quick_error! {
    pub enum MyError<'a> {
        Foo(e: SomeError<'a>) { }
    }
}

crumblingstatue avatar Mar 22 '16 19:03 crumblingstatue

Well, unfortunately generic arguments almost impossible to implement in current macro system. At least not for arbitrary generic parameters. Waiting for stable libmacro to make this possible.

But with the lifetimes there is a second issue: according to docs most of functionality of Error is for 'static bound, so I'm not sure it's too useful. (I've used to think that Any was required for Error, but can't find any references to it, maybe it was recently changed)

tailhook avatar Mar 22 '16 21:03 tailhook

I actually found a better way to represent my error that doesn't involve lifetimes, so this is not a blocker for me anymore.

crumblingstatue avatar Mar 22 '16 21:03 crumblingstatue

Even basic support for generics would be of enormous benefit to me... is there any chance we could get this working? I tried fiddling with the code, but it's truly arcane to me. :)

alexreg avatar Jul 09 '16 23:07 alexreg

@tailhook Are you aware of https://danielkeep.github.io/rust-parse-generics/doc/parse_macros/ ? This may make the job of adding support for generics a lot easier. And right now, I'd pay for generics support! :)

alexreg avatar Jul 10 '16 22:07 alexreg

No, I'm not. Looks interesting. Does it work for stable rust?

tailhook avatar Jul 10 '16 22:07 tailhook

Not sure, but I believe so. I got pointed to this by someone on IRC.

Here’s the GitHub: https://github.com/DanielKeep/rust-parse-generics

Let me know what you think.

On 10 Jul 2016, at 23:18, Paul Colomiets [email protected] wrote:

No, I'm not. Looks interesting. Does it work for stable rust?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tailhook/quick-error/issues/20#issuecomment-231614231, or mute the thread https://github.com/notifications/unsubscribe/AAEF3CQ0sAbGalkIDzpmIlhUbwKJgjq3ks5qUW-tgaJpZM4HjksI.

alexreg avatar Jul 10 '16 22:07 alexreg