-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add impl From<Ordering> for i32
#89491
Conversation
This commit adds a first-class `From` conversion of `Ordering` into `i32`. `Ordering` is defined to be compatible with the return types of the various `...cmp...` routines in the C standard library, but the only way to convert an `Ordering` to an `i32` is with a non-obvious `as` cast. This commit adds a proper API for doing this and hides a "scary" `as` cast inside the `core` library.
(rust-highfive has picked a reviewer for you, use r? to override) |
Tagging libs-api. This would be insta-stable, so it needs team review. @lopopolo Where is |
😅 I didn't say this was documented. I meant to say that I'm implementing several "cmp" style routines as part of an oxidation project and being able to turn a nicely typed |
I was of the impression that such a conversion being common was not a requirement for adding This behavior is already possible with an |
It's not that it needs to be common, it's that the usefulness needs to outweigh the potential for an error-prone conversion. There's a proposal in #81642 to add I would propose that we merge #81642 (in some form) and then |
ooooooh I didn't know about this proposal. That looks like it would do the trick. One sticking point is it doesn't look like Lines 324 to 336 in e737694
This sounds good to me. Do we need to cut another ticket to add a |
@lopopolo Yes, please do submit a PR adding Also, I submitted rust-lang/nomicon#315 to clarify that adding such a |
thanks for the help @joshtriplett. The new PR is here: |
… r=joshtriplett Add `#[repr(i8)]` to `Ordering` Followup to rust-lang#89491 to allow `Ordering` to auto-derive `AsRepr` once the proposal to add `AsRepr` (rust-lang#81642) lands. cc `@joshtriplett`
… r=joshtriplett Add `#[repr(i8)]` to `Ordering` Followup to rust-lang#89491 to allow `Ordering` to auto-derive `AsRepr` once the proposal to add `AsRepr` (rust-lang#81642) lands. cc ``@joshtriplett``
This commit adds a first-class
From
conversion ofOrdering
intoi32
.Ordering
is defined to be compatible with the return types of the various...cmp...
routines in the C standard library, but the only way to convert anOrdering
to ani32
is with a non-obviousas
cast.This commit adds a proper API for doing this and hides a "scary"
as
cast inside thecore
library.