I was writing some code recently and decided to really give “impl Trait in arguments” a good trial. It has so far seemed very nice for taking in convertible arguments like
fn new(tag: impl Into<Cow<'static, str>>) -> Self
I hit one more case where it seems it might be possible to provide some good readability sugar, but currently cannot be expressed; generic type arguments in trait implementations. As an example, currently you can write:
struct Foo(String);
impl<S: Into<String>> From<S> for Foo {
fn from(s: S) -> Self {
Foo(s.into())
}
}
instead it may be possible to support something like
impl From<impl Into<String>> for Foo {
fn from(s: ?????) -> Self {
Foo(s.into())
}
}
but, as you can see this runs into an issue with having the type named in multiple places.
I was wondering if anyone knows of any existing discussion around a feature like this, or whether there’s been discussion of extensions to the “impl Trait in arguments” feature that might help this nameability issue?