Skip to content

Instantly share code, notes, and snippets.

@pronebird
Created March 4, 2024 12:45
Show Gist options
  • Save pronebird/78af782e52662a0c4d9ea23fc657df8f to your computer and use it in GitHub Desktop.
Save pronebird/78af782e52662a0c4d9ea23fc657df8f to your computer and use it in GitHub Desktop.
Print rust struct byte by byte
unsafe fn any_as_u8_slice<T: Sized>(p: &T) -> &[u8] {
::core::slice::from_raw_parts(
(p as *const T) as *const u8,
::core::mem::size_of::<T>(),
)
}
let bytes: &[u8] = unsafe { any_as_u8_slice(&req) };
for byte in bytes {
print!("{:02x} ", byte);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment