-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add examples for Ord and PartialOrd traits in std docs #15253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
|
I missed that total order has
Note: I'm not remarking about the accuracy or precision of the definition. Just ease of comprehension. |
It doesn't have anything to do with the values contained in a specific array. As with all traits, it's a property of types. |
The type must fit with this |
A total ordering is a property of a type, not an array. |
@sfackler explained how my examples were ambiguous and I have used his explanation/examples to revise the example below. @thestinger, his explanation also also explained your comments which I didn't understand before. // A `type` which forms a total order is completely sortable
// `i32` forms a Total Order
let _entirelySortable = [1i32, -1, 7, 3, 5, 9]; // Sortable because `i32` is
// `f32` does not form a Total Order
let _partiallySortable1 = [1.0f32, -1.0, 7.0, std::f32::NAN];
// NAN's sorting order is undefined making this `type` unsortable
// (Is NAN before or after 3?)
// Still unsortable because `f32` supports NAN
let _partiallySortable2 = [1.0f32, -1.0, 7.0, 14.2]; // Also, not a total order My issue with the Ord page is without understanding Total order, it's difficult to know what it's talking about without thinking through that math example. If you look at #15217 where they assume people don't know the
Into: "Ah! This type has one unique sorting order with no exceptions! Obviously, if there is an exception, I have to use PartialOrd instead". The definition is certainly precise but it should be more readable (or have an example). Also, the range notation is much simpler and obvious once you know it. The issue with PartialOrd is that knowing what to use it for depends on knowing what Ord cannot be used for. I think making Ord more readable would be helpful. I grouped them together because they are related and an example in one could possibly be duplicated in the other because it is probably still pertinent. [EDIT] |
I don't think this is particularly actionable, or at least, any more than a general "most docs can be improved" kind of way. While they may be short, they are accurate, so I'm going to close this. Concrete improvements to any docs, including these docs, are welcome. |
Trait Ord and PartialOrd have cryptic explanations. An example would be helpful.
I thought these would be valid examples:
@steveklabnik You asked to be CCed on documentation bugs
The text was updated successfully, but these errors were encountered: