⇒ Currently not possible for expression in a system like Rust
An important term here is "HKT" ( h is stronger k inded t ypes). This is a feature of the type system that is not yet implemented in Rust. Haskell offers HKT. In the C ++ world, HKTs are known as "template templates."
But what is HKT, really?
Let's start slowly: what is a simple type, as we know it? We list some types: i32 , bool , String . These are all types ... you may have a value (variable) of these types. What about Vec<i32> ? This is also a simple type! You can have a variable like Vec<i32> , no problem!
We want to group these types together; we call this categorization "type view". If we want to speak very abstractly (about types of types), we choose other words kind in this case. There is even a notation for type types. For our simple types above we say: types of these types
*
Yes, just a star, very easy. Designations make sense later!
Allows you to search for types that are different from our simple types. Mutex<HashMap<Vec<i32>, String>> ? No, this is rather complicated, perhaps, but it still has the form * , and we can still have a variable of this type.
How about Vec ? Yes, we omitted the angle brackets. Yes, this is really a different type! Can we have a variable of type Vec ? Not! The vector of what ?!
This view is referred to as:
* -> *
It just says: give me the regular type ( * ) and I will return the regular type! Give the normal type i32 this thing ( Vec ) and it will return the normal type Vec<i32> ! It is also called a type constructor because it is used to build types. We can even go further:
* -> * -> *
This is a bit strange because it is related to currying and reads odd for a non-Haskell programmer. But that means: give me two types, and I will return the type. Think of an example ... Result ! The constructor of the Result type returns the concrete type Result<A, B> after you have provided two specific types A and B
The term higher type types applies only to all types of types that are not * , which are type constructors.
In your example
When you write struct Bar<T: Foo> , you want T have the form * -> * , which means: you can specify one type of T and get a simple type. But, as I said, this is not yet expressed in Rust. To use a similar syntax, we can assume that this may work in the future:
The syntax for<> borrowed from the "higher ranking" (HRTB) , which can be used today to abstract throughout life (most often used with closure).
References
If you want to know more about this topic, here are a few links:
Bonus : a solution to your problem if related type constructors are implemented (I think, since there is no way to test)!
We should take a detour in our implementation, since the RFC will not allow passing Rc as a type parameter directly. He does not introduce HKT directly, so to speak. But, as Nico claims in his blog, we can have the same flexibility and power as HKT with related type constructors, using the so-called "family traits."
For more information, you really should read Niko's blog entries. Difficult topics are explained well enough that even I can understand them more or less!
EDIT : I just noticed that Niko actually used the Arc / Rc example on his blog! I completely forgot about it and thought about the code above myself ... but maybe my subconscious mind was still remembered, because I choose several names in the same way as Nico did. In any case, here it is (perhaps better) the problem .