These can be directly implemented with from_le_bytes or from_be_bytes from the standard library.
The names of the functions can be different than I suggest here, decode_f32(buf: [u8; 4]) -> f32 is very close to fn read_f32(buf: &[u8]) -> f32, the only real difference is that the size of the input buffer is fixed.
It would be useful to have functions that convert between
[u8; N]
and number primitive types, whereN
is the size in bytes of that number type.Public api example:
These can be directly implemented with
from_le_bytes
orfrom_be_bytes
from the standard library.The names of the functions can be different than I suggest here,
decode_f32(buf: [u8; 4]) -> f32
is very close tofn read_f32(buf: &[u8]) -> f32
, the only real difference is that the size of the input buffer is fixed.