Hello, Is there was to put endianness to get bytes from Struct like so
Hello, Is there was to put endianness to get bytes from Struct like so
std::slice::from_raw_parts((my_struct as *const _) as *const u8, std::mem::size_of::<MyStruct>())
No any search results
You already invited:
1 Answers
Nora
Upvotes from:
Don’t rely on the as *const _ technique as the compiler can rearrange fields, even beyond reordering and alignment - the Rust compiler optimises memory layout much more than a C or C++ compiler would
Take a look at the byteorder crate, which has helper functions for writing fields in little or big endian format