Announcing `async fn` and return-position `impl Trait` in traits (blog.rust-lang.org)
from clot27@lemm.ee to rust@programming.dev on 21 Dec 2023 15:05
https://lemm.ee/post/18690884

#rust

threaded - newest

2xsaiko@discuss.tchncs.de on 21 Dec 2023 15:28 next collapse

Whoa, very cool! Can’t wait for 1.75.

sugar_in_your_tea@sh.itjust.works on 21 Dec 2023 16:44 collapse

-> impl Trait in public traits

That’s a bummer. This works:

trait Base {
  fn op(&self);
}
trait Child : Base {
  fn other_op(&self);
}

trait A {
  fn some_fn(val: impl Base) {
    val.op();
  }
}

fn some_fn(val: impl Child) {
  val.op();
  val.other_op();
}

So it seems like returning an impl Child in a trait that binds impl Base should also work.

Hopefully this change means we’ll see more of this kind of thing in the upcoming releases.