Type parameter versus type alias in trait

To quote a very old RFC:

An example
trait Generics<A, B, C, D, E> {
    fn other_stuff();
}

trait Assocs {
    type A;
    type B;
    type C;
    type D;
    type E;
    
    fn other_stuff();
}

fn call_other_stuff_generics<A, B, C, D, E, T> ()
where
    T : Generics<A, B, C, D, E>,
{
    T::other_stuff()
}

fn call_other_stuff_assocs<T : Assocs> ()
{
    T::other_stuff()
}

As well as:

  • Note that sometimes type inference can be too smart for its own good, so the "importing a crate could break existing code" is a real issue in current Rust.
2 Likes