atomic-rs icon indicating copy to clipboard operation
atomic-rs copied to clipboard

Enum can't work as expected.

Open rise0chen opened this issue 2 years ago • 3 comments

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
 #[repr(align(2))]
pub enum Test {
    A,
    B(u8),
}

Test::A maybe is 0x0000 or 0xXX00, so it maybe not equal when transmute to u16.

rise0chen avatar Jan 17 '22 11:01 rise0chen

You're right, enums will not work with this crate. Only types which have no paddings bytes and no invalid values will work. This effectively constraints it to structs with no padding bytes.

Amanieu avatar Jan 17 '22 21:01 Amanieu

#[repr(align(4))]
pub struct Test {
    a: u8,
    b: u16,
}

Does this struct have paddings bytes?

rise0chen avatar Jan 18 '22 06:01 rise0chen

Yes it does.

Amanieu avatar Jan 18 '22 13:01 Amanieu