use packed_struct::prelude::*;
use packed_struct_codegen::*;
#[derive(PrimitiveEnum_u8, Clone, Copy, Debug, PartialEq)]
pub enum Enum {
Zero,
One,
}
fn main() {
for x in Enum::all_variants().iter() {
let prim = x.to_primitive();
let parsed = Enum::from_primitive(prim);
println!("{:?} {} {:?}", x, prim, parsed);
}
}
The following code:
prints
instead of the expected
This is caused by
mut d
being set to0
https://github.com/hashmismatch/packed_struct.rs/blob/51f779d923c48eed1b321d46181c5ef848fd05a0/packed_struct_codegen/src/primitive_enum.rs#L233 and immediately incremented on the first iteration https://github.com/hashmismatch/packed_struct.rs/blob/51f779d923c48eed1b321d46181c5ef848fd05a0/packed_struct_codegen/src/primitive_enum.rs#L271