Only Bounds
29 points by asb
29 points by asb
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?
I appreciate the keyword: without it, the reader has to know what all the magic traits are. Especially if the list of magic traits can grow over time: if I saw T: Aligned in the future, I wouldn't realize it implies ?Sized. Whereas seeing the unfamiliar keyword only I'm prompted to look it up.
I think it's for complimentary traits, if you do MaybeSized you are getting Move + Destruct + ... by default