Hello,
I have two structs S1
and S2
and I want to write code that is generic and can use either. So I introduce a trait T
. Alas, one method has an opaque return type (a closure). How can I do this? Thanks!
trait T {
type F: Fn(String) -> String;
fn f() -> Self::F;
}
struct S1 {}
impl T for S1 {
// error[E0658]: `impl Trait` in type aliases is unstable
type F = impl Fn(String) -> String;
fn f() -> Self::F {
|s| { format!("Yo! {}", s) }
}
}
struct S2 {}
impl T for S2 {
// error[E0658]: `impl Trait` in type aliases is unstable
type F = impl Fn(String) -> String;
fn f() -> Self::F {
|s| { format!("Hey! {}", s) }
}
}
Best, Oliver