I was going implement Debug for a type to support the :x? syntax in formatting (it's for debug printing in hexadecimal). I'm not sure if it's widely used, but indeed it's mentioned in the std doc and I do have potential usages for it.
The question is, the docs says :x? should also be supported through the trait Debug, but the Formatter type doesn't have a method to tell whether Debug is called by :? or :x?. After some investigation into the compiler, I found that this information is captured in the Formatter's flags. So I had a try:
called Debug with flags 0
called Debug with flags 4
called Debug with flags 16
called Debug with flags 32
So, the flags indeed tell us how the trait is called. However, the flags method is deprecated, so it should not be used in new code. Then what is the idiomatic way to support the x? syntax? Or is this syntax actually also going to be deprecated?
Some discussion in the tracking issue of the original "debug hex" feature. Seems there wasn't a consensus between just providing a simple getter or whether there should be a more generic and future-proof API for getting the various formatting flags.
I misspelled the format specifier in my earlier post (fixed now), but OP's code wouldn't compile with LowerHex, as :x? still calls Debug, not LowerHex.
Thanks for pointing me to that tracking issue! At the bottom there seems to be a PR related to this. So I guess right now the way to implement this is still relying on the flags method until someday a new API is proposed?