0

Given:

trait Trait {}

trait SuperTrait: Trait {}

If I have a Box<dyn SuperTrait> how could I get a Box<dyn Trait> (or &mut dyn Trait)? e.g.

fn func1(x: Box<dyn SuperTrait>) {
    func2(x)
}

fn func2(x: Box<dyn Trait>) {
    
}

Trait and func2 are in a separate crate so I can't really modify their definitions

Ben
  • 2,661
  • 2
  • 15
  • 28
  • 2
    I think this question might be answered by https://stackoverflow.com/questions/28632968/why-doesnt-rust-support-trait-object-upcasting (I'm not casting a vote but letting you confirm or not whether it's a duplicate) – Denys Séguret Aug 12 '21 at 20:20

0 Answers0