What is the idiomatic rust way to do
u32, f32 <-> [u8;4]?
Do you want to do big endian or small endian? Whatever format it’s stored in memory.
Well, most direct way would be either an
as cast for
f32 or a
std::mem::transmute() although that needs unsafe code.
The usual terminology is “big endian”, “little endian”, and sometimes “native endian” to reflect the endianness of the local machine. The terms arise from an historic 1980 essay by Danny Cohen, titled “On holy wars and a plea for peace”.
Edit: they’re stable since Rust 1.32.0 https://doc.rust-lang.org/std/primitive.usize.html#method.to_be_bytes
Does this require unstable library features ‘int_to_from_bytes’ or is there another way to use it?