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
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.)
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)
The text was updated successfully, but these errors were encountered: