39
submitted 1 year ago by clot27@lemm.ee to c/rust@programming.dev
you are viewing a single comment's thread
view the rest of the comments
[-] sugar_in_your_tea@sh.itjust.works -1 points 1 year ago* (last edited 1 year 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.

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

Rust

6569 readers
37 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 2 years ago
MODERATORS