-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Cast a number to a c-style enum #2132
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I think |
Yeah, I ended up doing:
but it would be nice to have this as a feature of "as". |
Could this be another use for overloaded integer literals? Or would that be a bridge too far? |
In any case, marking as RFC since it is a language change. |
I don't think the actual use case involved a literal—if you already know, when writing the code, which value you want, you should probably write the variant's name anyway. Autoconverting literals to enum values seems like a bad idea. |
yeah, that was a bit of a contrived example. I actually wanted to convert some arbitrary uint data into an opcode enum for alting |
This seems like a case for a macro. Something that will generate a function |
@marijnh Quite right -- I wasn't thinking. |
Doing it with a macro would require that the macro also define the enum, so that it knows the names and values, which I think would make for an ugly enum declaration. I would maybe prefer to use an attribute. This could also be done with reflection and I think it should: |
continues in #3868 , closing this as a dupe |
Implement `Copy`/`Clone` for closures Implement RFC [#2132](rust-lang/rfcs#2132) (tracking issue: #44490). NB: I'm not totally sure about the whole feature gates thing, that's my first PR of this kind...
- Change `#[kani::proof]` expansion so it doesn't include `#[no_mangle]` but includes `[allow(dead_code)]`. (rust-lang#661 and rust-lang#689). - Add a check for harnesses with arguments and merge the checks into one function (rust-lang#1919). Co-authored-by: Zyad Hassan <88045115+zhassan-aws@users.noreply.github.com>
It doesn't seem there is any way to do this:
( v == Y )
Useful for interfacing with c libraries, writing DCPU16 emulators (!!!), etc. Possible?
The text was updated successfully, but these errors were encountered: