Rollup merge of #66002 - lzutao:stablilize-float_to_from_bytes, r=SimonSapin
Stabilize float_to_from_bytes feature FCP completed in https://github.com/rust-lang/rust/issues/60446#issuecomment-548440175 Closes #60446
This commit is contained in:
commit
5b707f8ca9
2 changed files with 12 additions and 24 deletions
|
@ -466,11 +466,10 @@ impl f32 {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(float_to_from_bytes)]
|
|
||||||
/// let bytes = 12.5f32.to_be_bytes();
|
/// let bytes = 12.5f32.to_be_bytes();
|
||||||
/// assert_eq!(bytes, [0x41, 0x48, 0x00, 0x00]);
|
/// assert_eq!(bytes, [0x41, 0x48, 0x00, 0x00]);
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
|
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_be_bytes(self) -> [u8; 4] {
|
pub fn to_be_bytes(self) -> [u8; 4] {
|
||||||
self.to_bits().to_be_bytes()
|
self.to_bits().to_be_bytes()
|
||||||
|
@ -482,11 +481,10 @@ impl f32 {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(float_to_from_bytes)]
|
|
||||||
/// let bytes = 12.5f32.to_le_bytes();
|
/// let bytes = 12.5f32.to_le_bytes();
|
||||||
/// assert_eq!(bytes, [0x00, 0x00, 0x48, 0x41]);
|
/// assert_eq!(bytes, [0x00, 0x00, 0x48, 0x41]);
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
|
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_le_bytes(self) -> [u8; 4] {
|
pub fn to_le_bytes(self) -> [u8; 4] {
|
||||||
self.to_bits().to_le_bytes()
|
self.to_bits().to_le_bytes()
|
||||||
|
@ -504,7 +502,6 @@ impl f32 {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(float_to_from_bytes)]
|
|
||||||
/// let bytes = 12.5f32.to_ne_bytes();
|
/// let bytes = 12.5f32.to_ne_bytes();
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// bytes,
|
/// bytes,
|
||||||
|
@ -515,7 +512,7 @@ impl f32 {
|
||||||
/// }
|
/// }
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
|
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_ne_bytes(self) -> [u8; 4] {
|
pub fn to_ne_bytes(self) -> [u8; 4] {
|
||||||
self.to_bits().to_ne_bytes()
|
self.to_bits().to_ne_bytes()
|
||||||
|
@ -526,11 +523,10 @@ impl f32 {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(float_to_from_bytes)]
|
|
||||||
/// let value = f32::from_be_bytes([0x41, 0x48, 0x00, 0x00]);
|
/// let value = f32::from_be_bytes([0x41, 0x48, 0x00, 0x00]);
|
||||||
/// assert_eq!(value, 12.5);
|
/// assert_eq!(value, 12.5);
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
|
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_be_bytes(bytes: [u8; 4]) -> Self {
|
pub fn from_be_bytes(bytes: [u8; 4]) -> Self {
|
||||||
Self::from_bits(u32::from_be_bytes(bytes))
|
Self::from_bits(u32::from_be_bytes(bytes))
|
||||||
|
@ -541,11 +537,10 @@ impl f32 {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(float_to_from_bytes)]
|
|
||||||
/// let value = f32::from_le_bytes([0x00, 0x00, 0x48, 0x41]);
|
/// let value = f32::from_le_bytes([0x00, 0x00, 0x48, 0x41]);
|
||||||
/// assert_eq!(value, 12.5);
|
/// assert_eq!(value, 12.5);
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
|
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_le_bytes(bytes: [u8; 4]) -> Self {
|
pub fn from_le_bytes(bytes: [u8; 4]) -> Self {
|
||||||
Self::from_bits(u32::from_le_bytes(bytes))
|
Self::from_bits(u32::from_le_bytes(bytes))
|
||||||
|
@ -563,7 +558,6 @@ impl f32 {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(float_to_from_bytes)]
|
|
||||||
/// let value = f32::from_ne_bytes(if cfg!(target_endian = "big") {
|
/// let value = f32::from_ne_bytes(if cfg!(target_endian = "big") {
|
||||||
/// [0x41, 0x48, 0x00, 0x00]
|
/// [0x41, 0x48, 0x00, 0x00]
|
||||||
/// } else {
|
/// } else {
|
||||||
|
@ -571,7 +565,7 @@ impl f32 {
|
||||||
/// });
|
/// });
|
||||||
/// assert_eq!(value, 12.5);
|
/// assert_eq!(value, 12.5);
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
|
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_ne_bytes(bytes: [u8; 4]) -> Self {
|
pub fn from_ne_bytes(bytes: [u8; 4]) -> Self {
|
||||||
Self::from_bits(u32::from_ne_bytes(bytes))
|
Self::from_bits(u32::from_ne_bytes(bytes))
|
||||||
|
|
|
@ -479,11 +479,10 @@ impl f64 {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(float_to_from_bytes)]
|
|
||||||
/// let bytes = 12.5f64.to_be_bytes();
|
/// let bytes = 12.5f64.to_be_bytes();
|
||||||
/// assert_eq!(bytes, [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
/// assert_eq!(bytes, [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
|
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_be_bytes(self) -> [u8; 8] {
|
pub fn to_be_bytes(self) -> [u8; 8] {
|
||||||
self.to_bits().to_be_bytes()
|
self.to_bits().to_be_bytes()
|
||||||
|
@ -495,11 +494,10 @@ impl f64 {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(float_to_from_bytes)]
|
|
||||||
/// let bytes = 12.5f64.to_le_bytes();
|
/// let bytes = 12.5f64.to_le_bytes();
|
||||||
/// assert_eq!(bytes, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]);
|
/// assert_eq!(bytes, [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]);
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
|
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_le_bytes(self) -> [u8; 8] {
|
pub fn to_le_bytes(self) -> [u8; 8] {
|
||||||
self.to_bits().to_le_bytes()
|
self.to_bits().to_le_bytes()
|
||||||
|
@ -517,7 +515,6 @@ impl f64 {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(float_to_from_bytes)]
|
|
||||||
/// let bytes = 12.5f64.to_ne_bytes();
|
/// let bytes = 12.5f64.to_ne_bytes();
|
||||||
/// assert_eq!(
|
/// assert_eq!(
|
||||||
/// bytes,
|
/// bytes,
|
||||||
|
@ -528,7 +525,7 @@ impl f64 {
|
||||||
/// }
|
/// }
|
||||||
/// );
|
/// );
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
|
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_ne_bytes(self) -> [u8; 8] {
|
pub fn to_ne_bytes(self) -> [u8; 8] {
|
||||||
self.to_bits().to_ne_bytes()
|
self.to_bits().to_ne_bytes()
|
||||||
|
@ -539,11 +536,10 @@ impl f64 {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(float_to_from_bytes)]
|
|
||||||
/// let value = f64::from_be_bytes([0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
/// let value = f64::from_be_bytes([0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
|
||||||
/// assert_eq!(value, 12.5);
|
/// assert_eq!(value, 12.5);
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
|
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_be_bytes(bytes: [u8; 8]) -> Self {
|
pub fn from_be_bytes(bytes: [u8; 8]) -> Self {
|
||||||
Self::from_bits(u64::from_be_bytes(bytes))
|
Self::from_bits(u64::from_be_bytes(bytes))
|
||||||
|
@ -554,11 +550,10 @@ impl f64 {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(float_to_from_bytes)]
|
|
||||||
/// let value = f64::from_le_bytes([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]);
|
/// let value = f64::from_le_bytes([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x29, 0x40]);
|
||||||
/// assert_eq!(value, 12.5);
|
/// assert_eq!(value, 12.5);
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
|
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_le_bytes(bytes: [u8; 8]) -> Self {
|
pub fn from_le_bytes(bytes: [u8; 8]) -> Self {
|
||||||
Self::from_bits(u64::from_le_bytes(bytes))
|
Self::from_bits(u64::from_le_bytes(bytes))
|
||||||
|
@ -576,7 +571,6 @@ impl f64 {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// #![feature(float_to_from_bytes)]
|
|
||||||
/// let value = f64::from_ne_bytes(if cfg!(target_endian = "big") {
|
/// let value = f64::from_ne_bytes(if cfg!(target_endian = "big") {
|
||||||
/// [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
|
/// [0x40, 0x29, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
|
||||||
/// } else {
|
/// } else {
|
||||||
|
@ -584,7 +578,7 @@ impl f64 {
|
||||||
/// });
|
/// });
|
||||||
/// assert_eq!(value, 12.5);
|
/// assert_eq!(value, 12.5);
|
||||||
/// ```
|
/// ```
|
||||||
#[unstable(feature = "float_to_from_bytes", issue = "60446")]
|
#[stable(feature = "float_to_from_bytes", since = "1.40.0")]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_ne_bytes(bytes: [u8; 8]) -> Self {
|
pub fn from_ne_bytes(bytes: [u8; 8]) -> Self {
|
||||||
Self::from_bits(u64::from_ne_bytes(bytes))
|
Self::from_bits(u64::from_ne_bytes(bytes))
|
||||||
|
|
Loading…
Reference in a new issue