3 ms·
> If a Foozle can be Ding, Ping, Zing or Number(n) where I promise n is from 0 to 199, that all fits in a byte if the compiler is willing to work with me by sto
by loeg 5y ago
> If a Foozle can be Ding, Ping, Zing or Number(n) where I promise n is from 0 to 199, that all fits in a byte if the compiler is willing to work with me by storing Ding, Ping and Zing as magic sentinels in the niche range 200 to 255 and I'm willing to trade the small runtime cost for the memory usage win.
Yeah, that would be cool. I think it would make sense to represent this as a repr(u8) enum with a range-limited Number variant. Something like:
#[repr(u8)]
enum Foozle {
Ding,
Ping,
Zing,
Number(u8 in 200..=255), // or whatever range syntax
}