Derive Macro bytemuck_derive::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.

§Example

#[derive(Copy, Clone, NoUninit, ByteEq)]
#[repr(C)]
struct Test {
  a: u32,
  b: char,
  c: f32,
}