Type-erasing dyn traits in Rust

59 points kimamor 17 comments

In Rust, Box<dyn Any> lets you store any type and recover it later, but what if you don’t want the concrete type? What if you want to go back to a Box<dyn SomeTrait> instead?

It is possible to just store Box<dyn SomeTrait> in Box<dyn Any>. But can we do this without double boxing?