diff options
Diffstat (limited to 'src/buffer/mod.rs')
-rw-r--r-- | src/buffer/mod.rs | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/src/buffer/mod.rs b/src/buffer/mod.rs index df21fe0..2ccd9b0 100644 --- a/src/buffer/mod.rs +++ b/src/buffer/mod.rs @@ -1,13 +1,12 @@ use crate::raw; -#[cfg(maybe_uninit)] use core::mem::MaybeUninit; -use core::{mem, slice, str}; +use core::{slice, str}; #[cfg(feature = "no-panic")] use no_panic::no_panic; -const NAN: &'static str = "NaN"; -const INFINITY: &'static str = "inf"; -const NEG_INFINITY: &'static str = "-inf"; +const NAN: &str = "NaN"; +const INFINITY: &str = "inf"; +const NEG_INFINITY: &str = "-inf"; /// Safe API for formatting floating point numbers to text. /// @@ -19,10 +18,7 @@ const NEG_INFINITY: &'static str = "-inf"; /// assert_eq!(printed, "1.234"); /// ``` pub struct Buffer { - #[cfg(maybe_uninit)] bytes: [MaybeUninit<u8>; 24], - #[cfg(not(maybe_uninit))] - bytes: [u8; 24], } impl Buffer { @@ -31,14 +27,8 @@ impl Buffer { #[inline] #[cfg_attr(feature = "no-panic", no_panic)] pub fn new() -> Self { - // assume_init is safe here, since this is an array of MaybeUninit, which does not need - // to be initialized. - #[cfg(maybe_uninit)] let bytes = [MaybeUninit::<u8>::uninit(); 24]; - #[cfg(not(maybe_uninit))] - let bytes = unsafe { mem::uninitialized() }; - - Buffer { bytes: bytes } + Buffer { bytes } } /// Print a floating point number into this buffer and return a reference to @@ -125,7 +115,7 @@ impl Sealed for f32 { #[inline] fn is_nonfinite(self) -> bool { const EXP_MASK: u32 = 0x7f800000; - let bits = unsafe { mem::transmute::<f32, u32>(self) }; + let bits = self.to_bits(); bits & EXP_MASK == EXP_MASK } @@ -134,7 +124,7 @@ impl Sealed for f32 { fn format_nonfinite(self) -> &'static str { const MANTISSA_MASK: u32 = 0x007fffff; const SIGN_MASK: u32 = 0x80000000; - let bits = unsafe { mem::transmute::<f32, u32>(self) }; + let bits = self.to_bits(); if bits & MANTISSA_MASK != 0 { NAN } else if bits & SIGN_MASK != 0 { @@ -154,7 +144,7 @@ impl Sealed for f64 { #[inline] fn is_nonfinite(self) -> bool { const EXP_MASK: u64 = 0x7ff0000000000000; - let bits = unsafe { mem::transmute::<f64, u64>(self) }; + let bits = self.to_bits(); bits & EXP_MASK == EXP_MASK } @@ -163,7 +153,7 @@ impl Sealed for f64 { fn format_nonfinite(self) -> &'static str { const MANTISSA_MASK: u64 = 0x000fffffffffffff; const SIGN_MASK: u64 = 0x8000000000000000; - let bits = unsafe { mem::transmute::<f64, u64>(self) }; + let bits = self.to_bits(); if bits & MANTISSA_MASK != 0 { NAN } else if bits & SIGN_MASK != 0 { |