+ /// ```
+ /// #![feature(int_to_from_bytes)]
+ ///
+ /// let bytes = 0x12345678i32.to_be_bytes();
+ /// assert_eq!(bytes, [0x12, 0x34, 0x56, 0x78]);
+ /// ```
+ #[unstable(feature = "int_to_from_bytes", issue = "49792")]
+ #[inline]
+ pub fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {
+ self.to_be().to_ne_bytes()
+ }
+
+ /// Return the memory representation of this integer as a byte array in
+ /// little-endian byte order.
+ ///
+ /// # Examples
+ ///
+ /// ```
+ /// #![feature(int_to_from_bytes)]
+ ///
+ /// let bytes = 0x12345678i32.to_le_bytes();
+ /// assert_eq!(bytes, [0x78, 0x56, 0x34, 0x12]);
+ /// ```
+ #[unstable(feature = "int_to_from_bytes", issue = "49792")]
+ #[inline]
+ pub fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {
+ self.to_le().to_ne_bytes()
+ }
+
+ /// Return the memory representation of this integer as a byte array in
+ /// native byte order.
+ ///
+ /// As the target platform's native endianness is used, portable code
+ /// should use [`to_be_bytes`] or [`to_le_bytes`], as appropriate,
+ /// instead.
+ ///
+ /// [`to_be_bytes`]: #method.to_be_bytes
+ /// [`to_le_bytes`]: #method.to_le_bytes