bytemuck

Derive Macro ByteEq

Source
#[derive(ByteEq)]
Expand description

Derive the PartialEq and Eq trait for a type

The macro implements PartialEq and Eq by casting both sides of the comparison to a byte slice and then compares those.

§Warning

Since this implements a byte wise comparison, the behavior of floating point numbers does not match their usual comparison behavior. Additionally other custom comparison behaviors of the individual fields are also ignored. This also does not implement StructuralPartialEq / StructuralEq like PartialEq / Eq would. This means you can’t pattern match on the values.

§Examples

#[derive(Copy, Clone, NoUninit, ByteEq)]
#[repr(C)]
struct Test {
  a: u32,
  b: char,
  c: f32,
}
#[derive(Copy, Clone, ByteEq)]
#[repr(C)]
struct Test<const N: usize> {
  a: [u32; N],
}
unsafe impl<const N: usize> NoUninit for Test<N> {}