A Rust trick: use method-call resolution order to implement trait fallback 0 ▲ Guilherme Souza 52 minutes ago · Tech · hide Before explaining what the trick is and how it works, I'll take a general example: let's say in a Rust codebase or library you find a better way of doing something, but you still want to keep compatibility with the rest of the codebase or ecosystem. Say you have a new trait Awesome that does what Debug does, but better (for some definition of better). You may want to express code that can consume a value that it either Awesome or Debug like this: fn do_it(value: impl Awesome or Debug) { if impls!(value, Awesome) { // use Awesome's logic } else { // use Debug's logic } } This syntax is invented, but the idea is: if the caller gives you a type that implements Awesome use its implementation, otherwise fallback to Debug. A concrete example of such a need is the crate maud, that declares the Render trait, which is a better Display because it handles html-escaping more efficiently. A simplifier version of it is: trait Render { /// Append the data to the buffer, /// escaping it as necessary… Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town