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

You are designing a trait `Container` that yields one element type per implementing type, and you never want a single type to implement it for multiple element types. Which design is correct and why?

// Option A trait Container { type Item; fn get(&self, i: usize) -> Option<&Self::Item>; } // Option B trait Container<T> { fn get(&self, i: usize) -> Option<&T>; }