1
Fork 0

Individual docs for {from,to}_*_bytes

This commit is contained in:
Andre Bogus 2018-08-17 22:20:09 +02:00
parent d8af8b66d9
commit 90b7c5acbc

View file

@ -192,7 +192,7 @@ mod wrapping;
macro_rules! int_impl { macro_rules! int_impl {
($SelfT:ty, $ActualT:ident, $UnsignedT:ty, $BITS:expr, $Min:expr, $Max:expr, $Feature:expr, ($SelfT:ty, $ActualT:ident, $UnsignedT:ty, $BITS:expr, $Min:expr, $Max:expr, $Feature:expr,
$EndFeature:expr, $rot:expr, $rot_op:expr, $rot_result:expr, $swap_op:expr, $swapped:expr, $EndFeature:expr, $rot:expr, $rot_op:expr, $rot_result:expr, $swap_op:expr, $swapped:expr,
$reversed:expr) => { $reversed:expr, $le_bytes:expr, $be_bytes:expr) => {
doc_comment! { doc_comment! {
concat!("Returns the smallest value that can be represented by this integer type. concat!("Returns the smallest value that can be represented by this integer type.
@ -2063,23 +2063,25 @@ $EndFeature, "
self.to_be().to_ne_bytes() self.to_be().to_ne_bytes()
} }
/// Return the memory representation of this integer as a byte array in doc_comment! {
/// big-endian (network) byte order. concat!("Return the memory representation of this integer as a byte array in
/// big-endian (network) byte order.
/// # Examples
/// # Examples
/// ```
/// #![feature(int_to_from_bytes)] ```
/// #![feature(int_to_from_bytes)]
/// let bytes = 0x12_34_56_78_i32.to_be_bytes();
/// assert_eq!(bytes, [0x12, 0x34, 0x56, 0x78]); let bytes = ", $swap_op, stringify!($SelfT), ".to_be_bytes();
/// ``` assert_eq!(bytes, ", $be_bytes, ");
#[unstable(feature = "int_to_from_bytes", issue = "52963")] ```"),
#[rustc_const_unstable(feature = "const_int_conversion")] #[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[inline] #[rustc_const_unstable(feature = "const_int_conversion")]
#[cfg(not(stage0))] #[inline]
pub const fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] { #[cfg(not(stage0))]
self.to_be().to_ne_bytes() pub const fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {
self.to_be().to_ne_bytes()
}
} }
/// no docs here /// no docs here
@ -2090,23 +2092,25 @@ $EndFeature, "
self.to_le().to_ne_bytes() self.to_le().to_ne_bytes()
} }
/// Return the memory representation of this integer as a byte array in doc_comment! {
/// little-endian byte order. concat!("Return the memory representation of this integer as a byte array in
/// little-endian byte order.
/// # Examples
/// # Examples
/// ```
/// #![feature(int_to_from_bytes)] ```
/// #![feature(int_to_from_bytes)]
/// let bytes = 0x12_34_56_78_i32.to_le_bytes();
/// assert_eq!(bytes, [0x78, 0x56, 0x34, 0x12]); let bytes = ", $swap_op, stringify!($SelfT), ".to_le_bytes();
/// ``` assert_eq!(bytes, ", $le_bytes, ");
#[unstable(feature = "int_to_from_bytes", issue = "52963")] ```"),
#[rustc_const_unstable(feature = "const_int_conversion")] #[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[inline] #[rustc_const_unstable(feature = "const_int_conversion")]
#[cfg(not(stage0))] #[inline]
pub const fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] { #[cfg(not(stage0))]
self.to_le().to_ne_bytes() pub const fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {
self.to_le().to_ne_bytes()
}
} }
/// no docs here /// no docs here
@ -2117,30 +2121,37 @@ $EndFeature, "
unsafe { mem::transmute(self) } unsafe { mem::transmute(self) }
} }
/// Return the memory representation of this integer as a byte array in doc_comment! {
/// native byte order. concat!("
/// Return the memory representation of this integer as a byte array in
/// As the target platform's native endianness is used, portable code native byte order.
/// should use [`to_be_bytes`] or [`to_le_bytes`], as appropriate,
/// instead. As the target platform's native endianness is used, portable code
/// should use [`to_be_bytes`] or [`to_le_bytes`], as appropriate,
/// [`to_be_bytes`]: #method.to_be_bytes instead.
/// [`to_le_bytes`]: #method.to_le_bytes
/// [`to_be_bytes`]: #method.to_be_bytes
/// # Examples [`to_le_bytes`]: #method.to_le_bytes
///
/// ``` # Examples
/// #![feature(int_to_from_bytes)]
/// ```
/// let bytes = i32::min_value().to_be().to_ne_bytes(); #![feature(int_to_from_bytes)]
/// assert_eq!(bytes, [0x80, 0, 0, 0]);
/// ``` let bytes = ", $swap_op, stringify!($SelfT), ".to_ne_bytes();
#[unstable(feature = "int_to_from_bytes", issue = "52963")] assert_eq!(bytes, if cfg!(target_endian = \"big\") {
#[rustc_const_unstable(feature = "const_int_conversion")] ", $be_bytes, "
#[inline] } else {
#[cfg(not(stage0))] ", $le_bytes, "
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] { });
unsafe { mem::transmute(self) } ```"),
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
#[cfg(not(stage0))]
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
unsafe { mem::transmute(self) }
}
} }
/// no docs here /// no docs here
@ -2151,23 +2162,25 @@ $EndFeature, "
Self::from_be(Self::from_ne_bytes(bytes)) Self::from_be(Self::from_ne_bytes(bytes))
} }
/// Create an integer value from its representation as a byte array in doc_comment! {
/// big endian. concat!("Create an integer value from its representation as a byte array in
/// big endian.
/// # Examples
/// # Examples
/// ```
/// #![feature(int_to_from_bytes)] ```
/// #![feature(int_to_from_bytes)]
/// let int = i32::from_be_bytes([0x12, 0x34, 0x56, 0x78]);
/// assert_eq!(int, 0x12_34_56_78); let value = ", stringify!($SelfT), "::from_be_bytes(", $be_bytes, ");
/// ``` assert_eq!(value, ", $swap_op, ");
#[unstable(feature = "int_to_from_bytes", issue = "52963")] ```"),
#[rustc_const_unstable(feature = "const_int_conversion")] #[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[inline] #[rustc_const_unstable(feature = "const_int_conversion")]
#[cfg(not(stage0))] #[inline]
pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self { #[cfg(not(stage0))]
Self::from_be(Self::from_ne_bytes(bytes)) pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
Self::from_be(Self::from_ne_bytes(bytes))
}
} }
/// no docs here /// no docs here
@ -2178,23 +2191,26 @@ $EndFeature, "
Self::from_le(Self::from_ne_bytes(bytes)) Self::from_le(Self::from_ne_bytes(bytes))
} }
/// Create an integer value from its representation as a byte array in doc_comment! {
/// little endian. concat!("
/// Create an integer value from its representation as a byte array in
/// # Examples little endian.
///
/// ``` # Examples
/// #![feature(int_to_from_bytes)]
/// ```
/// let int = i32::from_le_bytes([0x12, 0x34, 0x56, 0x78]); #![feature(int_to_from_bytes)]
/// assert_eq!(int, 0x78_56_34_12);
/// ``` let value = ", stringify!($SelfT), "::from_le_bytes(", $le_bytes, ");
#[unstable(feature = "int_to_from_bytes", issue = "52963")] assert_eq!(value, ", $swap_op, ");
#[rustc_const_unstable(feature = "const_int_conversion")] ```"),
#[inline] #[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_conversion")]
pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self { #[inline]
Self::from_le(Self::from_ne_bytes(bytes)) #[cfg(not(stage0))]
pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
Self::from_le(Self::from_ne_bytes(bytes))
}
} }
/// no docs here /// no docs here
@ -2205,56 +2221,65 @@ $EndFeature, "
unsafe { mem::transmute(bytes) } unsafe { mem::transmute(bytes) }
} }
/// Create an integer value from its memory representation as a byte doc_comment! {
/// array in native endianness. concat!("Create an integer value from its memory representation as a byte
/// array in native endianness.
/// As the target platform's native endianness is used, portable code
/// likely wants to use [`from_be_bytes`] or [`from_le_bytes`], as As the target platform's native endianness is used, portable code
/// appropriate instead. likely wants to use [`from_be_bytes`] or [`from_le_bytes`], as
/// appropriate instead.
/// [`from_be_bytes`]: #method.from_be_bytes
/// [`from_le_bytes`]: #method.from_le_bytes [`from_be_bytes`]: #method.from_be_bytes
/// [`from_le_bytes`]: #method.from_le_bytes
/// # Examples
/// # Examples
/// ```
/// #![feature(int_to_from_bytes)] ```
/// #![feature(int_to_from_bytes)]
/// let int = i32::from_be(i32::from_ne_bytes([0x80, 0, 0, 0]));
/// assert_eq!(int, i32::min_value()); let value = ", stringify!($SelfT), "::from_ne_bytes(if cfg!(target_endian = \"big\") {
/// ``` ", $be_bytes, "
#[unstable(feature = "int_to_from_bytes", issue = "52963")] } else {
#[rustc_const_unstable(feature = "const_int_conversion")] ", $le_bytes, "
#[inline] });
#[cfg(not(stage0))] assert_eq!(value, ", $swap_op, ");
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self { ```"),
unsafe { mem::transmute(bytes) } #[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
#[cfg(not(stage0))]
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
unsafe { mem::transmute(bytes) }
}
} }
} }
} }
#[lang = "i8"] #[lang = "i8"]
impl i8 { impl i8 {
int_impl! { i8, i8, u8, 8, -128, 127, "", "", 2, "-0x7e", "0xa", "0x12", "0x12", "0x48" } int_impl! { i8, i8, u8, 8, -128, 127, "", "", 2, "-0x7e", "0xa", "0x12", "0x12", "0x48",
"[0x12]", "[0x12]" }
} }
#[lang = "i16"] #[lang = "i16"]
impl i16 { impl i16 {
int_impl! { i16, i16, u16, 16, -32768, 32767, "", "", 4, "-0x5ffd", "0x3a", "0x1234", "0x3412", int_impl! { i16, i16, u16, 16, -32768, 32767, "", "", 4, "-0x5ffd", "0x3a", "0x1234", "0x3412",
"0x2c48" } "0x2c48", "[0x34, 0x12]", "[0x12, 0x34]" }
} }
#[lang = "i32"] #[lang = "i32"]
impl i32 { impl i32 {
int_impl! { i32, i32, u32, 32, -2147483648, 2147483647, "", "", 8, "0x10000b3", "0xb301", int_impl! { i32, i32, u32, 32, -2147483648, 2147483647, "", "", 8, "0x10000b3", "0xb301",
"0x12345678", "0x78563412", "0x1e6a2c48" } "0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78]" }
} }
#[lang = "i64"] #[lang = "i64"]
impl i64 { impl i64 {
int_impl! { i64, i64, u64, 64, -9223372036854775808, 9223372036854775807, "", "", 12, int_impl! { i64, i64, u64, 64, -9223372036854775808, 9223372036854775807, "", "", 12,
"0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412", "0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412",
"0x6a2c48091e6a2c48" } "0x6a2c48091e6a2c48", "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]" }
} }
#[lang = "i128"] #[lang = "i128"]
@ -2262,22 +2287,26 @@ impl i128 {
int_impl! { i128, i128, u128, 128, -170141183460469231731687303715884105728, int_impl! { i128, i128, u128, 128, -170141183460469231731687303715884105728,
170141183460469231731687303715884105727, "", "", 16, 170141183460469231731687303715884105727, "", "", 16,
"0x13f40000000000000000000000004f76", "0x4f7613f4", "0x12345678901234567890123456789012", "0x13f40000000000000000000000004f76", "0x4f7613f4", "0x12345678901234567890123456789012",
"0x12907856341290785634129078563412", "0x48091e6a2c48091e6a2c48091e6a2c48" "0x12907856341290785634129078563412", "0x48091e6a2c48091e6a2c48091e6a2c48",
} "[0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, \
0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, \
0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12]" }
} }
#[cfg(target_pointer_width = "16")] #[cfg(target_pointer_width = "16")]
#[lang = "isize"] #[lang = "isize"]
impl isize { impl isize {
int_impl! { isize, i16, u16, 16, -32768, 32767, "", "", 4, "-0x5ffd", "0x3a", "0x1234", int_impl! { isize, i16, u16, 16, -32768, 32767, "", "", 4, "-0x5ffd", "0x3a", "0x1234",
"0x3412", "0x2c48" } "0x3412", "0x2c48", "[0x34, 0x12]", "[0x12, 0x34]" }
} }
#[cfg(target_pointer_width = "32")] #[cfg(target_pointer_width = "32")]
#[lang = "isize"] #[lang = "isize"]
impl isize { impl isize {
int_impl! { isize, i32, u32, 32, -2147483648, 2147483647, "", "", 8, "0x10000b3", "0xb301", int_impl! { isize, i32, u32, 32, -2147483648, 2147483647, "", "", 8, "0x10000b3", "0xb301",
"0x12345678", "0x78563412", "0x1e6a2c48" } "0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78]" }
} }
#[cfg(target_pointer_width = "64")] #[cfg(target_pointer_width = "64")]
@ -2285,7 +2314,8 @@ impl isize {
impl isize { impl isize {
int_impl! { isize, i64, u64, 64, -9223372036854775808, 9223372036854775807, "", "", int_impl! { isize, i64, u64, 64, -9223372036854775808, 9223372036854775807, "", "",
12, "0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412", 12, "0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412",
"0x6a2c48091e6a2c48" } "0x6a2c48091e6a2c48", "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]" }
} }
// Emits the correct `cttz` call, depending on the size of the type. // Emits the correct `cttz` call, depending on the size of the type.
@ -2305,7 +2335,7 @@ macro_rules! uint_cttz_call {
macro_rules! uint_impl { macro_rules! uint_impl {
($SelfT:ty, $ActualT:ty, $BITS:expr, $MaxV:expr, $Feature:expr, $EndFeature:expr, ($SelfT:ty, $ActualT:ty, $BITS:expr, $MaxV:expr, $Feature:expr, $EndFeature:expr,
$rot:expr, $rot_op:expr, $rot_result:expr, $swap_op:expr, $swapped:expr, $rot:expr, $rot_op:expr, $rot_result:expr, $swap_op:expr, $swapped:expr,
$reversed:expr ) => { $reversed:expr, $le_bytes:expr, $be_bytes:expr) => {
doc_comment! { doc_comment! {
concat!("Returns the smallest value that can be represented by this integer type. concat!("Returns the smallest value that can be represented by this integer type.
@ -3960,23 +3990,25 @@ $EndFeature, "
self.to_be().to_ne_bytes() self.to_be().to_ne_bytes()
} }
/// Return the memory representation of this integer as a byte array in doc_comment! {
/// big-endian (network) byte order. concat!("Return the memory representation of this integer as a byte array in
/// big-endian (network) byte order.
/// # Examples
/// # Examples
/// ```
/// #![feature(int_to_from_bytes)] ```
/// #![feature(int_to_from_bytes)]
/// let bytes = 0x12_34_56_78_i32.to_be_bytes();
/// assert_eq!(bytes, [0x12, 0x34, 0x56, 0x78]); let bytes = ", $swap_op, stringify!($SelfT), ".to_be_bytes();
/// ``` assert_eq!(bytes, ", $be_bytes, ");
#[unstable(feature = "int_to_from_bytes", issue = "52963")] ```"),
#[rustc_const_unstable(feature = "const_int_conversion")] #[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[inline] #[rustc_const_unstable(feature = "const_int_conversion")]
#[cfg(not(stage0))] #[inline]
pub const fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] { #[cfg(not(stage0))]
self.to_be().to_ne_bytes() pub const fn to_be_bytes(self) -> [u8; mem::size_of::<Self>()] {
self.to_be().to_ne_bytes()
}
} }
/// no docs here /// no docs here
@ -3987,23 +4019,25 @@ $EndFeature, "
self.to_le().to_ne_bytes() self.to_le().to_ne_bytes()
} }
/// Return the memory representation of this integer as a byte array in doc_comment! {
/// little-endian byte order. concat!("Return the memory representation of this integer as a byte array in
/// little-endian byte order.
/// # Examples
/// # Examples
/// ```
/// #![feature(int_to_from_bytes)] ```
/// #![feature(int_to_from_bytes)]
/// let bytes = 0x12_34_56_78_i32.to_le_bytes();
/// assert_eq!(bytes, [0x78, 0x56, 0x34, 0x12]); let bytes = ", $swap_op, stringify!($SelfT), ".to_le_bytes();
/// ``` assert_eq!(bytes, ", $le_bytes, ");
#[unstable(feature = "int_to_from_bytes", issue = "52963")] ```"),
#[rustc_const_unstable(feature = "const_int_conversion")] #[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[inline] #[rustc_const_unstable(feature = "const_int_conversion")]
#[cfg(not(stage0))] #[inline]
pub const fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] { #[cfg(not(stage0))]
self.to_le().to_ne_bytes() pub const fn to_le_bytes(self) -> [u8; mem::size_of::<Self>()] {
self.to_le().to_ne_bytes()
}
} }
/// no docs here /// no docs here
@ -4014,30 +4048,37 @@ $EndFeature, "
unsafe { mem::transmute(self) } unsafe { mem::transmute(self) }
} }
/// Return the memory representation of this integer as a byte array in doc_comment! {
/// native byte order. concat!("
/// Return the memory representation of this integer as a byte array in
/// As the target platform's native endianness is used, portable code native byte order.
/// should use [`to_be_bytes`] or [`to_le_bytes`], as appropriate,
/// instead. As the target platform's native endianness is used, portable code
/// should use [`to_be_bytes`] or [`to_le_bytes`], as appropriate,
/// [`to_be_bytes`]: #method.to_be_bytes instead.
/// [`to_le_bytes`]: #method.to_le_bytes
/// [`to_be_bytes`]: #method.to_be_bytes
/// # Examples [`to_le_bytes`]: #method.to_le_bytes
///
/// ``` # Examples
/// #![feature(int_to_from_bytes)]
/// ```
/// let bytes = i32::min_value().to_be().to_ne_bytes(); #![feature(int_to_from_bytes)]
/// assert_eq!(bytes, [0x80, 0, 0, 0]);
/// ``` let bytes = ", $swap_op, stringify!($SelfT), ".to_ne_bytes();
#[unstable(feature = "int_to_from_bytes", issue = "52963")] assert_eq!(bytes, if cfg!(target_endian = \"big\") {
#[rustc_const_unstable(feature = "const_int_conversion")] ", $be_bytes, "
#[inline] } else {
#[cfg(not(stage0))] ", $le_bytes, "
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] { });
unsafe { mem::transmute(self) } ```"),
#[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
#[cfg(not(stage0))]
pub const fn to_ne_bytes(self) -> [u8; mem::size_of::<Self>()] {
unsafe { mem::transmute(self) }
}
} }
/// no docs here /// no docs here
@ -4048,23 +4089,25 @@ $EndFeature, "
Self::from_be(Self::from_ne_bytes(bytes)) Self::from_be(Self::from_ne_bytes(bytes))
} }
/// Create an integer value from its representation as a byte array in doc_comment! {
/// big endian. concat!("Create an integer value from its representation as a byte array in
/// big endian.
/// # Examples
/// # Examples
/// ```
/// #![feature(int_to_from_bytes)] ```
/// #![feature(int_to_from_bytes)]
/// let int = i32::from_be_bytes([0x12, 0x34, 0x56, 0x78]);
/// assert_eq!(int, 0x12_34_56_78); let value = ", stringify!($SelfT), "::from_be_bytes(", $be_bytes, ");
/// ``` assert_eq!(value, ", $swap_op, ");
#[unstable(feature = "int_to_from_bytes", issue = "52963")] ```"),
#[rustc_const_unstable(feature = "const_int_conversion")] #[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[inline] #[rustc_const_unstable(feature = "const_int_conversion")]
#[cfg(not(stage0))] #[inline]
pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self { #[cfg(not(stage0))]
Self::from_be(Self::from_ne_bytes(bytes)) pub const fn from_be_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
Self::from_be(Self::from_ne_bytes(bytes))
}
} }
/// no docs here /// no docs here
@ -4075,23 +4118,26 @@ $EndFeature, "
Self::from_le(Self::from_ne_bytes(bytes)) Self::from_le(Self::from_ne_bytes(bytes))
} }
/// Create an integer value from its representation as a byte array in doc_comment! {
/// little endian. concat!("
/// Create an integer value from its representation as a byte array in
/// # Examples little endian.
///
/// ``` # Examples
/// #![feature(int_to_from_bytes)]
/// ```
/// let int = i32::from_le_bytes([0x12, 0x34, 0x56, 0x78]); #![feature(int_to_from_bytes)]
/// assert_eq!(int, 0x78_56_34_12);
/// ``` let value = ", stringify!($SelfT), "::from_le_bytes(", $le_bytes, ");
#[unstable(feature = "int_to_from_bytes", issue = "52963")] assert_eq!(value, ", $swap_op, ");
#[rustc_const_unstable(feature = "const_int_conversion")] ```"),
#[inline] #[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[cfg(not(stage0))] #[rustc_const_unstable(feature = "const_int_conversion")]
pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self { #[inline]
Self::from_le(Self::from_ne_bytes(bytes)) #[cfg(not(stage0))]
pub const fn from_le_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
Self::from_le(Self::from_ne_bytes(bytes))
}
} }
/// no docs here /// no docs here
@ -4102,37 +4148,44 @@ $EndFeature, "
unsafe { mem::transmute(bytes) } unsafe { mem::transmute(bytes) }
} }
/// Create an integer value from its memory representation as a byte doc_comment! {
/// array in native endianness. concat!("Create an integer value from its memory representation as a byte
/// array in native endianness.
/// As the target platform's native endianness is used, portable code
/// likely wants to use [`from_be_bytes`] or [`from_le_bytes`], as As the target platform's native endianness is used, portable code
/// appropriate instead. likely wants to use [`from_be_bytes`] or [`from_le_bytes`], as
/// appropriate instead.
/// [`from_be_bytes`]: #method.from_be_bytes
/// [`from_le_bytes`]: #method.from_le_bytes [`from_be_bytes`]: #method.from_be_bytes
/// [`from_le_bytes`]: #method.from_le_bytes
/// # Examples
/// # Examples
/// ```
/// #![feature(int_to_from_bytes)] ```
/// #![feature(int_to_from_bytes)]
/// let int = i32::from_be(i32::from_ne_bytes([0x80, 0, 0, 0]));
/// assert_eq!(int, i32::min_value()); let value = ", stringify!($SelfT), "::from_ne_bytes(if cfg!(target_endian = \"big\") {
/// ``` ", $be_bytes, "
#[unstable(feature = "int_to_from_bytes", issue = "52963")] } else {
#[rustc_const_unstable(feature = "const_int_conversion")] ", $le_bytes, "
#[inline] });
#[cfg(not(stage0))] assert_eq!(value, ", $swap_op, ");
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self { ```"),
unsafe { mem::transmute(bytes) } #[unstable(feature = "int_to_from_bytes", issue = "52963")]
#[rustc_const_unstable(feature = "const_int_conversion")]
#[inline]
#[cfg(not(stage0))]
pub const fn from_ne_bytes(bytes: [u8; mem::size_of::<Self>()]) -> Self {
unsafe { mem::transmute(bytes) }
}
} }
} }
} }
#[lang = "u8"] #[lang = "u8"]
impl u8 { impl u8 {
uint_impl! { u8, u8, 8, 255, "", "", 2, "0x82", "0xa", "0x12", "0x12", "0x48" } uint_impl! { u8, u8, 8, 255, "", "", 2, "0x82", "0xa", "0x12", "0x12", "0x48", "[0x12]",
"[0x12]" }
/// Checks if the value is within the ASCII range. /// Checks if the value is within the ASCII range.
@ -4658,45 +4711,55 @@ impl u8 {
#[lang = "u16"] #[lang = "u16"]
impl u16 { impl u16 {
uint_impl! { u16, u16, 16, 65535, "", "", 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48" } uint_impl! { u16, u16, 16, 65535, "", "", 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48",
"[0x34, 0x12]", "[0x12, 0x34]" }
} }
#[lang = "u32"] #[lang = "u32"]
impl u32 { impl u32 {
uint_impl! { u32, u32, 32, 4294967295, "", "", 8, "0x10000b3", "0xb301", "0x12345678", uint_impl! { u32, u32, 32, 4294967295, "", "", 8, "0x10000b3", "0xb301", "0x12345678",
"0x78563412", "0x1e6a2c48" } "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78]" }
} }
#[lang = "u64"] #[lang = "u64"]
impl u64 { impl u64 {
uint_impl! { u64, u64, 64, 18446744073709551615, "", "", 12, "0xaa00000000006e1", "0x6e10aa", uint_impl! { u64, u64, 64, 18446744073709551615, "", "", 12, "0xaa00000000006e1", "0x6e10aa",
"0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48" } "0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48",
"[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]" }
} }
#[lang = "u128"] #[lang = "u128"]
impl u128 { impl u128 {
uint_impl! { u128, u128, 128, 340282366920938463463374607431768211455, "", "", 16, uint_impl! { u128, u128, 128, 340282366920938463463374607431768211455, "", "", 16,
"0x13f40000000000000000000000004f76", "0x4f7613f4", "0x12345678901234567890123456789012", "0x13f40000000000000000000000004f76", "0x4f7613f4", "0x12345678901234567890123456789012",
"0x12907856341290785634129078563412", "0x48091e6a2c48091e6a2c48091e6a2c48" } "0x12907856341290785634129078563412", "0x48091e6a2c48091e6a2c48091e6a2c48",
"[0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, \
0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, \
0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12]" }
} }
#[cfg(target_pointer_width = "16")] #[cfg(target_pointer_width = "16")]
#[lang = "usize"] #[lang = "usize"]
impl usize { impl usize {
uint_impl! { usize, u16, 16, 65536, "", "", 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48" } uint_impl! { usize, u16, 16, 65536, "", "", 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48",
"[0x34, 0x12]", "[0x12, 0x34]" }
} }
#[cfg(target_pointer_width = "32")] #[cfg(target_pointer_width = "32")]
#[lang = "usize"] #[lang = "usize"]
impl usize { impl usize {
uint_impl! { usize, u32, 32, 4294967295, "", "", 8, "0x10000b3", "0xb301", "0x12345678", uint_impl! { usize, u32, 32, 4294967295, "", "", 8, "0x10000b3", "0xb301", "0x12345678",
"0x78563412", "0x1e6a2c48" } "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78]" }
} }
#[cfg(target_pointer_width = "64")] #[cfg(target_pointer_width = "64")]
#[lang = "usize"] #[lang = "usize"]
impl usize { impl usize {
uint_impl! { usize, u64, 64, 18446744073709551615, "", "", 12, "0xaa00000000006e1", "0x6e10aa", uint_impl! { usize, u64, 64, 18446744073709551615, "", "", 12, "0xaa00000000006e1", "0x6e10aa",
"0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48" } "0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48",
"[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]",
"[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]" }
} }
/// A classification of floating point numbers. /// A classification of floating point numbers.