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

Rust

6049 readers
34 users here now

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

Wormhole

[email protected]

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
[–] [email protected] -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.