You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can I write a displaydoc impl for the following struct?
#[displaydoc("{kind}: {str_context}")]pubstructDataError{/// Broad category of the error.pubkind:DataErrorKind,/// Additional context, if available.pubstr_context:Option<&'static str>,}
This errors out with:
`std::option::Option<&str>` cannot be formatted with the default formatter
What I would like is to make an error that contains ": {str_context}" when Some and nothing when None.
Do I need to manually implement Display, or can I use displaydoc?
The text was updated successfully, but these errors were encountered:
Right now we don't have any support displaying options like this. We do have something similar on Path/PathBuf, where we will call display() transparently in the background, so I wouldn't be against adding some support for convenient formatting for Option.
I do have questions about the specific case you mentioned. It looks like you'd want to print "Some DataErrorKind Display: " with a trailing : and whitespace even when the str_context is None. Is this the correct behavior you'd like to see? Without knowing your specific usecase in detail my intuition is you'd want to show "Some DataErrorKind Display: some str_context" for the Some case and "SomeDataErrorKind Display" in the None case. I imagine we'd need something a bit more complicated to support the later case.
Without knowing your specific usecase in detail my intuition is you'd want to show "Some DataErrorKind Display: some str_context" for the Some case and "SomeDataErrorKind Display" in the None case.
Yes, that is what I meant. I would like to format with "{}: {}" when the context is Some and "{}" when the context is None. I was thinking a way to go about this would be to format the struct as a whole with "{}{}", where the second placeholder is ": {}" if Some or "" if None.
How can I write a displaydoc impl for the following struct?
This errors out with:
What I would like is to make an error that contains
": {str_context}"
when Some and nothing when None.Do I need to manually implement Display, or can I use displaydoc?
The text was updated successfully, but these errors were encountered: