Add option to derive Debug identical to Display
ypoluektovich opened this issue · comments
Feature request: in failure_derive, add an option to fail
attribute that would automatically generate a Debug implementation that is identical to (or, perhaps more appropriately, delegating to) the Display implementation (as generated by #[fail(display=...)]
).
Context:
I am defining my own Fail types, for example:
#[derive(Fail)]
#[fail(display = "Aborting by user request")]
pub struct AbortedByUser;
I am also using fn main() -> Result<(), failure::Error>
. This means that the std::process::Termination
trait comes into play, and its implementation for Result ends up calling eprintln!("Error: {:?}", err);
. If I derive Debug for my type, I get the output Error: AbortedByUser
, which is not ideal UX-wise. So I ended up doing this:
impl Debug for AbortedByUser {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
Display::fmt(self, f)
}
}
Now the program prints: Error: Aborting by user request
.
This was fine while I only had one such failure type, but then I added the second one for which I wanted the same kind of reporting experience. Obviously, I can remove most of the boilerpaste with a macro, but that's still a macro that I'd have to write and put somewhere in my code. It would be much nicer if I could just write something like #[fail(display = "Aborting by user request", debug_as_display)]
.
To increase the web's connectivity:
- relevant discussion in the tracking issue for
Termination
: rust-lang/rust#43301 (comment) - mentions exitfailure crate