Skip to content
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

Consider output of guard_unwrap #9

Closed
durka opened this issue Apr 11, 2021 · 0 comments
Closed

Consider output of guard_unwrap #9

durka opened this issue Apr 11, 2021 · 0 comments

Comments

@durka
Copy link
Owner

durka commented Apr 11, 2021

It is definitely possible to get better printing, but after playing with it I agree with you that it's better left to a later decision. I'll explain why.

The way the macro works is it calls itself over and over while deconstructing the expression, and finally calls $crate::__guard_output with all the pieces nicely separated. The way to customize the panic message is to swap out this output macro with a different one. This is the easy part and can be done by threading another argument all the way through the macro, so we can specify from the beginning the alternative output macro.

But there's another problem when printing: you can't assume "{:?}" will work 😞
You can print out stringified versions of the pattern and expression that didn't match, but reliably printing the debug format of the expression, or "<unknown>" if it doesn't even impl Debug, requires the unstable specialization feature (see debugit). (NB: this is a type system limitation, not a macro limitation, so it can't even be solved via a procedural macro.)

Originally posted by @durka in #8 (comment)

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

No branches or pull requests

1 participant