How can I access a method that has the same name as an enum variant?
This is not a particularly practical question – I just stumbled across this in Rust that I was surprised compiles, and want to understand more what is going on.
How to get an enum variant from its index?
I’m trying to write a high performance way to be able to convert between an enum variant (where none of the variants have data) and its index. Currently I am using a bunch of consts:
rust match access the subvariant field
tl;dr within a match
statement for an enum
with subvariants, how can I assign that subvariant to a variable?
How does the “as” operator convert enums to ints?
I was creating a Bit enum for a project of mine and I experienced some weird interaction with the as u32
(or any other type) syntax. I have Into<u8, u16, .. u128> implemented for my Bit enum so I mindlessly used Bit as u32
in a test of mine, sort of assuming it was syntactic sugar for .into()
. I ran some tests that failed, in trying to find the bug I spotted that my Bit enum was layed out like this:
How does the “as” operator convert enums to ints?
I was creating a Bit enum for a project of mine and I experienced some weird interaction with the as u32
(or any other type) syntax. I have Into<u8, u16, .. u128> implemented for my Bit enum so I mindlessly used Bit as u32
in a test of mine, sort of assuming it was syntactic sugar for .into()
. I ran some tests that failed, in trying to find the bug I spotted that my Bit enum was layed out like this:
How do `as u32` conversions work for enums?
I was creating a Bit enum for a project of mine and I experienced some weird interaction with the as u32
(or any other type) syntax. I have Into<u8, u16, .. u128> implemented for my Bit enum so I mindlessly used Bit as u32
in a test of mine, sort of assuming it was syntactic sugar for .into()
. I ran some tests that failed, in trying to find the bug I spotted that my Bit enum was layed out like this: