-
Notifications
You must be signed in to change notification settings - Fork 14k
Implement PartialOrd and Ord for Discriminant
#106418
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
base: main
Are you sure you want to change the base?
Changes from 5 commits
3237c31
2fd6091
db4656f
2ff6f20
dbc3154
36ce983
ec64db7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1106,18 +1106,31 @@ impl<T> fmt::Debug for Discriminant<T> { | |
| } | ||
| } | ||
|
|
||
| #[stable(feature = "discriminant_ord", since = "CURRENT_RUSTC_VERSION")] | ||
| impl<T> cmp::PartialOrd for Discriminant<T> { | ||
| fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { | ||
| self.0.partial_cmp(&other.0) | ||
| } | ||
| } | ||
|
|
||
| #[stable(feature = "discriminant_ord", since = "CURRENT_RUSTC_VERSION")] | ||
| impl<T> cmp::Ord for Discriminant<T> { | ||
| fn cmp(&self, other: &Self) -> cmp::Ordering { | ||
| self.0.cmp(&other.0) | ||
| } | ||
| } | ||
|
|
||
| /// Returns a value uniquely identifying the enum variant in `v`. | ||
| /// | ||
| /// If `T` is not an enum, calling this function will not result in undefined behavior, but the | ||
| /// return value is unspecified. | ||
| /// | ||
| /// # Stability | ||
| /// | ||
| /// The discriminant of an enum variant may change if the enum definition changes. A discriminant | ||
| /// of some variant will not change between compilations with the same compiler. See the [Reference] | ||
| /// for more information. | ||
| /// `Discriminant` is an opaque wrapper around the enum discriminant, therefore it's value will | ||
| /// change when the enum definition changes. See the [Reference] for more information. | ||
| /// | ||
| /// [Reference]: ../../reference/items/enumerations.html#custom-discriminant-values-for-fieldless-enumerations | ||
| /// [Reference]: ../../reference/items/enumerations.html#discriminants | ||
|
||
| /// | ||
| /// # Examples | ||
| /// | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.