3 ms·
Like three different kinds, too! // Old-style generics; monomorphized // with S as an "input" type of MyTrait fn foo<S, T: MyTrait<S>>
by Gankro 12y ago
Like three different kinds, too!
// Old-style generics; monomorphized
// with S as an "input" type of MyTrait
fn foo<S, T: MyTrait<S>>(elem: T) { ... }
// Where-clause-style generics; monomorphized,
// with S as an "output" (associated) type of MyTrait
fn foo<S, T>(elem: T)
where T: MyTrait<Thing = S> { ... }
// Trait objects; dynamic dispatch
fn foo(elem: Box<MyTrait>) { ... }
- kimundi 12y agoWell, the first two are really just the same thing :P
- Gankro 12y agoEh, with the new oprhan/impl rules associated and uh... not... associated(...?) types have developed quite a schism.
- dbaupp 12y agoWell, the first two confusingly change two variables at once: the things that are the same (which I presume is what kimundi meant) are fn foo<S, T: MyTrait<S>>(elem: T) { ... } fn foo<S, T>(elem: T) where T: MyTrait<S> { ... } and fn foo<S, T: MyTrait<Thing = S>>(elem: T) { ... } fn foo<S, T>(elem: T) where T: MyTrait<Thing = S> { ... }