Relative Content

Tag Archive for rustenums

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:

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: