-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow opting-out of the macro-generated Display implementation #360
Comments
I can see your point of view, and I think something akin to As a third avenue: #[derive(Debug, Snafu)]
enum ExtractionError {
#[snafu(display("failed to extract from record {position}"))]
Thing1 {
source: ExtractionErrorKind,
position: i32,
},
#[snafu(display("failed to extract from record"))]
Thing2 {
source: ExtractionErrorKind,
}
} It's hard to tell exactly why |
In this case, can you use |
I had the same idea 😉. Unfortunately, the implementation of fn main() {
let a_value = 42;
let a = {
format_args!("{a_value}")
};
println!("{a}");
}
|
I ran into the same issue when trying this at first. Sorry, I should have mentioned that.
Thanks, that nudged me in the right direction. Nonetheless, I would vote to keep this issue open, since there are probably other cases where custom I've also found another workaround: by implementing the expected format in |
Certainly. In fact, there’s been low level chatter about having some kind of
I think that unwrapping is the correct decision for that particular piece of data, but amusingly you could also create another error variant for the position itself being missing and use that instead of unwrapping.
That’s an interesting idea, but I’d probably go with your shim type instead, just to avoid the confusion. |
I am using gettext to translate errors to user facing error messages in their preferred language. It would be necessary to be able to implement Display for this. |
would you mind chiming in on #254? If possible, I’d rather like to extend SNAFU to interact nicely with such functionality |
As gettext can't parse attribute macros and I am also drilling very deeply into some errors this isn't really feasible. I might just work around it by implementing a separate method that creates a string. |
Thank you so much for this very useful library!
After using it for a while in some projects, I found one thing that bothers me a bit. For some errors, I would like to have the opportunity to implement
Display
myself. Currently, I get a compile error when trying that. Perhaps, the syntax could be#[snafu(display(false))]
.As a motivating example, consider the following error, with the current display attribute.
Since
position
is not guaranteed to exist, I cannot simply format the field. Instead, I have an intermediate allocation to format the field. With a customDisplay
implementation, formatting would be no problem.Alternatives
I see two major alternatives, but I'm open to any other suggestions:
Snafu
forExtractionError
and implement the required traits myself. This would work, but goes against why I'm using Snafu in the first place.Snafu
, I will probably go down that road.The text was updated successfully, but these errors were encountered: