-
Notifications
You must be signed in to change notification settings - Fork 1
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
Support as = "..."
annotation
#16
Comments
Thank you for the detailed issue / feature description! |
I wonder if there's an even more general mechanism to provide custom debug formatting.
Which would desugar to the same code as you showed, but it would allow convenient, arbitrary wrapping or modification of the value. It would even cover the functionality of |
I'm a bit wary of writing arbitrary code into strings, though I couldn't say exactly why. It's definitely not something I've seen in any of the other Two specific concerns I'd have would be:
I did come across I personally still favour an annotation that takes a path to an |
I've started using
custom_debug
to reduce the amount of hand-writtenDebug
boilerplate in the codebases I work with. It's especially useful when there's, e.g., a single field in a large enum that you want to exclude, where otherwise you would have to rewrite theDebug
logic for the whole enum, or at least the whole variant.However, one thing I'm struggling with is the proliferation of
fmt_*
methods I end up with, for the different formatting possibilities. This is exacerbated by the fact that thewith = "..."
annotation doesn't 'compose' well with other crates likehex_fmt
, nor with theformat = "..."
annotation.I think a solution to this could be to introduce an
as = "..."
annotation, which would de-sugar thusly:It could even compose with
format = "..."
:The value given to
as = "..."
for a field of typeT
would have to refer to a function with signaturefn(&T) -> impl fmt::Debug
.I'm not very familiar with derive macros, but if this is something you'd be open to adding I could look to create a PR.
The text was updated successfully, but these errors were encountered: