Lokathor / bytemuck

A crate for mucking around with piles of bytes
https://docs.rs/bytemuck
Apache License 2.0
697 stars 77 forks source link

derive(Zeroable) on fieldful enums and repr(C) enums #257

Open zachs18 opened 1 month ago

zachs18 commented 1 month ago

Closes #230.

Allows deriving Zeroable on enums where:

  1. The enum is #[repr(Int)], #[repr(C)], or #[repr(C, Int)],
  2. There is a variant with discriminant 0,
  3. The variant with discriminant 0 is either fieldless, or all of its fields are Zeroable.

Also allows using the "perfect derive with additional bounds" from #196 for Zeroable on enums, where the fields for the "perfect derive" are from the variant with discriminant 0 (see the MyOption example on line 189 of derive/src/lib.rs).

Internal changes: