Currently impl Trait is only allowed as the return type of a free-standing functions and inherent methods. I would like to see it opened to a few more positions.
Local variable signatures
can already be simulated by:
fn wrapper<T: Foo>(x: T) -> impl Foo { x }
let x = wrapper(bar());
Also,
let x: Option<impl Foo> = bar();
If bar returns Option<Baz>, Baz would be checked for an implementation of Foo.
Parameters of free-standing functions and methods
can be equivalent to:
Furthermore,
fn bar(x: Option<impl Foo>) { }
can be equivalent to:
fn bar<T: Foo>(x: Option<T>) { }
This cuts down a bit on boilerplate.
Other positions in return types of free-standing functions and methods
fn bar() -> Option<impl Foo> { }
Currently
impl Traitis only allowed as the return type of a free-standing functions and inherent methods. I would like to see it opened to a few more positions.Local variable signatures
can already be simulated by:
Also,
If
barreturnsOption<Baz>,Bazwould be checked for an implementation ofFoo.Parameters of free-standing functions and methods
can be equivalent to:
Furthermore,
can be equivalent to:
This cuts down a bit on boilerplate.
Other positions in return types of free-standing functions and methodsfn bar() -> Option<impl Foo> { }