visual
Use the Display trait if it's satisfied, fallback to Debug otherwise, and
if neither are implemented use a default string value.
Why
The typical "nice" way to display things is via the Display trait. However, sometimes
this trait is not available, but Debug is. Debug is easy to derive. In those cases
it would be nice to use Debug as a fallback.
Usage
use ;
If neither trait is implemented, the string representation will be the one defined by
visual::get_non_displayable_string(). This default label can be initialized to a custom value
once, by calling visual::set_non_displayable_string("value").
Credits
For the magic to work, I use the "autoderef hack" proposed by Lukas Kalbertodt, which in turn is based on David Tolnay's technique.
Links
- Documentation: docs.rs
- Crate: crates.io
- Repository: github.com