Downcast not from Any, but from any trait

On a second read, you might be asking for something different here, and my previous answer is perhaps what you expected in this following thread, (without explicitly asking for it)


Downcasting is implemented in terms of a method to retrieve a TypeId, and this is what Any provides. Downcasting to a type from Rc<dyn SomeOtherTrait> can’t work for just any other abitrary trait, but if you set up the trait accordingly, it could be feasible. In fact, it is possible to implement other traits that include Any-like capabilities already: AFAIR crates like mopa or downcast-rs present patterns of how to achieve this.

1 Like