Only Bounds

29 points by asb


rix0rrr

I must be missing something extremely obvious, but I'm struggling to see why we need the only keyword at all.

If we have the given trait hierarchy:

trait MaybeSized
trait MetadataSized: MaybeSized
trait Sized: MetadataSized

Then it seems natural to say:

fn by_ref<U>(u: &U)
where
    U: MaybeSized,  // <-- any type that extends MaybeSized (which happens to be all of them)
{}

From the article, only disables "some other default traits". But it seems that these traits can only be used with the only keyword, and it has to be clear from context which default traits need to be disabled... so is there any advantage to having the keyword altogether? Why not have the specific trait be "magic" and only-automatic?