Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumRustassociated types vs genericsSingle-choice MCQ

What is required to use a trait that has an associated type as a boxed trait object (dyn Trait)?

trait Producer { type Output; fn produce(&self) -> Self::Output; } struct P; impl Producer for P { type Output = i32; fn produce(&self) -> i32 { 42 } } fn main() { let b: Box<dyn Producer<Output = i32>> = Box::new(P); println!("{}", b.produce()); }