Derive Macro bytemuck::ByteHash

source ·
#[derive(ByteHash)]
Expand description

Derive the Hash trait for a type

The macro implements Hash by casting the value to a byte slice and hashing that.

§Warning

The hash does not match the standard library’s Hash derive.

§Examples

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