Use Cases for Rust Any Trait

Use-Case from the Documentation

The "Any" documentation gives an example where two traits, where one is Any and the other is Debug, are used in preferential order. The Any trait is used to check for an anticipated Concrete Type which is used preferentially to the Debug trait to print a debug message. This is one use case for the Any trait, although not my favorite.

Get a Unique Id for any concrete type

The Any type is implemented by assigning a unique global identifier to each concrete type that is cast into an Any. This allows us to not only destructure concrete types, but also this let's us implement truly dynamic dispatch. One example would be to implement a Duck Typed trait-like interface on any object that satisfies the interface requirements. This would be true duck typing as opposed to the nominal subtyping that is known as the traits system