Closed
Description
openedon Feb 1, 2017
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
let x: impl Foo = bar();
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
fn bar(x: impl Foo) { }
can be equivalent to:
fn bar<T: Foo>(x: T) { }
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> { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment