Downcasting Arcs in Rust

The Arc type is Rust’s thread-safe smart pointer, and like other pointer types in Rust (e.g., Box ), one can use the as keyword 1 to cast an Arc<MyStruct> into an Arc<dyn MyTrait> , as long as MyTrait is dyn compatible . What about casting it back from Arc<dyn MyTrait> to Arc<MyStruct> ? Well, here the plot thickens a bit. We can’t use the as keyword here, because that operation is inherently…