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

Rust

5989 readers
54 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
top 2 comments
sorted by: hot top controversial new old
[โ€“] 2xsaiko@discuss.tchncs.de 6 points 11 months ago

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

[โ€“] 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.