Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Add option to derive Debug identical to Display #327

Open
ypoluektovich opened this issue Oct 3, 2019 · 1 comment
Open

Add option to derive Debug identical to Display #327

ypoluektovich opened this issue Oct 3, 2019 · 1 comment

Comments

@ypoluektovich
Copy link

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)].

@ypoluektovich
Copy link
Author

To increase the web's connectivity:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant