This comes up periodically; the usual suggestion is to use the (unstable, nightly-only) specialization feature, as in these posts:
Related topics
| Topic | Replies | Views | Activity | |
|---|---|---|---|---|
| Use the dbg!(...) macro without requiring the Debug trait in parent functions? | 3 | 1399 | April 11, 2021 | |
| How to derive Debug when one of the types involved doesn't impl Debug? | 3 | 1339 | July 19, 2023 | |
| [SOLVED] Put trait bound Debug on generic type only during development | 3 | 1080 | September 9, 2016 | |
| Compile Time Type Reflection w/o Any? | 3 | 780 | July 6, 2020 | |
| Conditional print formatting, debugging using attribute macro | 2 | 1622 | July 25, 2019 |