A previous incarnation of this API that went though FCP in #49792, but stabilization was reverted while still in Nightly in favor of this API.
Implemented in #51919, conversions between all integer types and appropriately-sized arrays of u8, using the specified endianness:
impl $Int {
pub fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {…}
pub fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {…}
pub fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {…}
pub fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {…}
pub fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {…}
pub fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {…}
}
ne, le, and be mean native-endian, little-endian, and big-endian respectively. Native-endian means the target platform’s endianness. Those conversions are implemented as literally transmute and nothing else (but safe). The other conversions use swap or do not swap the byte order depending on the target’s endianness.
A previous incarnation of this API that went though FCP in #49792, but stabilization was reverted while still in Nightly in favor of this API.
Implemented in #51919, conversions between all integer types and appropriately-sized arrays of
u8, using the specified endianness:ne,le, andbemean native-endian, little-endian, and big-endian respectively. Native-endian means the target platform’s endianness. Those conversions are implemented as literallytransmuteand nothing else (but safe). The other conversions use swap or do not swap the byte order depending on the target’s endianness.