• sugar_in_your_tea@sh.itjust.works
    link
    fedilink
    arrow-up
    1
    arrow-down
    2
    ·
    edit-2
    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.