0

Is this type of polymorphism possible in Rust, or is it planned?

I.e.

trait R { ... }
struct S { ... }
impl R for S { ... }

let r: Box<R> = Box::new(S { ... });
let s: Box<S> = dynamic_cast<Box<S>>(r).expect("r is a boxed S");

I am aware that std::mem::transmute provides an unsafe way of doing this, but don't see any explicit support for dynamic_cast (which, I guess, is fine).

dhardy
  • 11,175
  • 7
  • 38
  • 46
  • 3
    This is referred to as *downcasting*. You should mark this as a duplicate of http://stackoverflow.com/q/27892375/155423 or http://stackoverflow.com/q/25246443/155423 or http://stackoverflow.com/q/33687447/155423 or (insert more search results here). – Shepmaster Dec 04 '15 at 20:03
  • Thanks. But up, down... you're clearly talking about tree roots not branches ;-) – dhardy Dec 05 '15 at 10:58

0 Answers0