this post was submitted on 21 Dec 2023
34 points (100.0% liked)

Rust

5999 readers
64 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] sugar_in_your_tea@sh.itjust.works -1 points 11 months ago* (last edited 11 months ago)

-> 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.