10 ms·
Could this be used to add an "Ord::clamp" or similar to the stdlib such that it's invisible (and thus wouldn't cause any conflict) to crates with an older "edit
by cesarb 9y ago
Could this be used to add an "Ord::clamp" or similar to the stdlib such that it's invisible (and thus wouldn't cause any conflict) to crates with an older "edition"?
- aturon 9y agoYes, it could! There aren't plans to do so yet, but it'd be worth spinning up a thread on internals about this.
- deleted 9y ago[deleted]
- Manishearth 9y agoI think for such things it's preferable to just have a `clamp` method as a static method, i.e. you call it with `Ord::clamp(foo, bar)` instead of `foo.clamp(bar)`. But yes, it could. Generally the trend seems to be to still try to avoid having actual breakages in the editions unless we _have_ to, and this seems like one of those cases where we don't. That said, adding Ord::clamp doesn't technically count as a breakage for Rust, Rust's stability guarantee does not include "we added a method to this trait/type and now you have to disambiguate via UFCS" or "we added a thing to this module and now you have to alias your import" because it's not really possible to have that stability guarantee and continue to evolve the stdlib. That said, given that Ord is in the prelude, the bar for adding stuff to that is much higher. And Rust also cares about the impact of not-technically-breaking changes like these, so we definitely wouldn't just add it as a method.