Here's an example for abstract types (as defined the RFC @Centril mentioned):
abstract type Foo: MyTrait<Item = i32>;
fn foo() -> Foo
Note: The concrete syntax is in flux (see debate about this in the tracking issue
Alternatively there was also an extensive debate about making it possible to name the output of a function by accessing its Output
associated type in Pre-Pre-RFC: async methods & bounding async fns I think that this would work best in addition to abstract types, not as a replacement.
I don't think this is coming. Generic structs require that you define type parameters for a reason (e.g. T
in struct Vec<T>)
. Type params are needed to name the type later, e.g. Vec<i32>
. With impl Trait
there would be no type parameters and the system can't work without them.
You're disregarding a major use case of impl Trait
. Instead of returning something like std::iter::Filter<std::iter::Map<std::vec::IntoIter<i32>
you can return impl Iterator<Item = i32>
. It makes it possible to conveniently not expose implementation details as public API.