Syntactically, I think this is what you want:
trait OuterTrait<T> {
fn use_type_parameter(t: T);
}
trait InnerTrait {}
type CombinedTypeOne<T: InnerTrait> = Option<OuterTrait<T>>;
type CombinedTypeTwo<T> where T: InnerTrait = Option<OuterTrait<T>>;
fn main() {}
In a larger sense, this makes sense. When you define a type, it has to either completely know what type it is, or have type parameters and be fully specified at the use site. In your example, the type StreamList
acts like it is completely specified. However, the right-hand side says "put in any concrete type", so you'd need to rectify the two.
Beyond that, the trait constraint goes on the "declaration" part of the alias, not the "definition" part. This mirrors how trait and function definitions work.
However, the first example has this warning:
warning: trait bounds are not (yet) enforced in type definitions [E0122]
type CombinedTypeOne<T: InnerTrait> = Option<OuterTrait<T>>;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The detailed explanation for E0122.
I believe that the second example has the same underlying problem, but the warning is missing — I'd guess this is a bug that should be reported. I think that overall, this means you cannot do what you want yet.
Additionally, you are trying to use a trait as a type (represented above as Option<OuterTrait>
. Although conceptually possible, I don't know how to actually construct an object that looks like that. It's more likely you want something like
type CombinedTypeOne<T, U: OuterTrait<T>> = Option<U>;
type CombinedTypeTwo<T, U> where U: OuterTrait<T> = Option<U>;
but that complains about unused type parameters. I can't reason through if the error makes sense or is a side-effect of the fact that this feature isn't enforced yet:
error: type parameter `T` is unused [E0091]
type CombinedTypeOne<T, U: OuterTrait<T>> = Option<U>;
^~~~~~~~~