Is there any way to fallback Debug?

Debug is not always implemented. Therefore, when we implement generic functions of types, we have have to choose either: Add where T:Debug, or give up dbg! or expect or other utilities.

Is that true? Is there any way to use debug string only when Debug is implemented and use another default string when is not implemented?

This comes up periodically; the usual suggestion is to use the (unstable, nightly-only) specialization feature, as in these posts:

2 Likes

The second one worked, with scary warning.
It would be useful for temporal dbg!

thank you.

Yes, the scary warning (applicable to both examples since they use feature(specialization), one of them just silences it) - it indicates that there needs to be found a way to do the same thing using feature(min_specialization) which is likely closer to how specialization will be allowed to be used in future Rust.

1 Like

Note that “the same thing” must not literally be “the same thing”. The proposed workarounds, e.g. the macro I made in the other thread, or your DebugAnything wrapper, really aren’t supposed to be used in production, because they’re (both) inherently unsound.


Thus, @Vill.Snow, that “scary warning” you currently get isn’t without reason.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.