Since big-endian and little-endian have to do with byte order, and since one u8
is one byte, wouldn't u8::from_be_bytes
and u8::from_le_bytes
always have the same behavior?
Yes, they have the same behavior. The byte-oriented functions (swap_bytes
and (from|to)_[bln]e(_bytes)?
) on u8
are provided for consistency with the larger integers, even though they have trivial implementations.
Among other things, this makes it easier to write macro code that is correct for all sizes of integer, rather than having to special-case u8
.