It appears to be smart enough to only use one byte for A, but not smart enough to use one byte for B, even though there are only 8*8=64 possibilities. Is there any way to coax Rust to figure this out or do I have to manually implement a more compact layout?
#![allow(dead_code)]
enum A {
L,
UL,
U,
UR,
R,
DR,
D,
DL,
}
enum B {
C(A, A),
}
fn main() {
println!("{:?}", std::mem::size_of::<A>()); // prints 1
println!("{:?}", std::mem::size_of::<B>()); // prints 2
}
A
is the size of au8
, and therefore there is two bytes required to fit twoA
s inB
, as there is no compile-time micro optimizations like this. Anyway, what if the packed version of this was slower to use than the unpacked version? – Freberg