Open dbrgn opened 8 years ago
Unfortunately, you can't. The problem is that the macro uses traits to dispatch things like Display
to the individual error cases. These traits often have to be implemented on non-local types; thus, the traits themselves must be local. This in turn means the macro has to define the traits anywhere it wants to use them, but it has no way of "hiding" them from other invocations of the macro.
Hence the above errors.
Without the ability to either construct identifiers or hide items, there's not a great deal I can really do about this. One solution would be to completely rewrite the macro from the ground-up to not use trait dispatch, but I don't have the time for that at the moment.
The simplest workaround is probably to just put each macro invocation in a little module and pull the error type out with use
a use in the parent module:
pub use error1::Error;
mod error1 { error_type! { ... } }
OK, I guess I'll live with that module workaround for now :)
I'll leave this open as a reminder that this could theoretically be improved. :)
Yeah, would definitely be nice.
How do I define multiple error structs using your macro in a single module?
For example, when I copy your error declaration (line 6-24) in
tests/quickie.rs
and change the name, I get the following compilation errors: