Clot@lemm.ee to Rust@programming.dev · 11 months agoAnnouncing async fn and return-position impl Trait in traitsblog.rust-lang.orgexternal-linkmessage-square2fedilinkarrow-up139arrow-down10cross-posted to: rust@lemmy.ml
arrow-up139arrow-down1external-linkAnnouncing async fn and return-position impl Trait in traitsblog.rust-lang.orgClot@lemm.ee to Rust@programming.dev · 11 months agomessage-square2fedilinkcross-posted to: rust@lemmy.ml
minus-squaresugar_in_your_tea@sh.itjust.workslinkfedilinkarrow-up1arrow-down2·edit-210 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.
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 bindsimpl Base
should also work.Hopefully this change means we’ll see more of this kind of thing in the upcoming releases.