Generic type of trait?

  1. I know we can do:
pub trait Foo {
  type Bar;
}
  1. Question: is there a way to do somethign like:
pub trait Foo {
  type Bar<T>;
}
  1. For one struct implementing Foo, we could have Bar = Vec. For another struct implementing Foo, we could have Bar=LinkedList. For a third struct implementing Foo, we could have Bar=HashSet.

This is Generic Associated Types, which is currently being worked on. It is such an early stage that it hasn't even been implemented on nightly yet.

traking issue
https://github.com/rust-lang/rust/issues/44265

1 Like