Created
March 4, 2024 12:45
-
-
Save pronebird/78af782e52662a0c4d9ea23fc657df8f to your computer and use it in GitHub Desktop.
Print rust struct byte by byte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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