This question already has an answer here:
- How to specify the representation type for an enum in Rust to interface with C++? 1 answer
Given a simple enum with a few un-typed values, it might be desirable that the size of this enum use a smaller integral type then the default. For example, this provides the ability to store the enum in an array of u8
.
enum MyEnum {
A = 0,
B,
C,
}
It's possible to use a u8
array and compare them against some constants, but I would like to have the benefit of using enums to ensure all possibilities are handled in a match statement.
How can this be specified so its size_of
matches the desired integer type?