From dae826b4e5fccf98f406ee240335434d433b666b Mon Sep 17 00:00:00 2001 From: Luro02 <24826124+Luro02@users.noreply.github.com> Date: Mon, 24 Feb 2020 12:19:37 +0100 Subject: [PATCH] improve (U)Float --- src/types/float.rs | 18 ++++++++++++------ src/types/ufloat.rs | 21 +++++++++++++-------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/types/float.rs b/src/types/float.rs index d03621d..7a1d262 100644 --- a/src/types/float.rs +++ b/src/types/float.rs @@ -2,17 +2,17 @@ use core::cmp::Ordering; use core::convert::TryFrom; use core::str::FromStr; -use derive_more::{Deref, Display}; +use derive_more::{AsRef, Deref, Display}; use crate::Error; -/// This is a wrapper type around an [`f32`] that can not be constructed +/// A wrapper type around an [`f32`] that can not be constructed /// with [`NaN`], [`INFINITY`] or [`NEG_INFINITY`]. /// /// [`NaN`]: core::f32::NAN /// [`INFINITY`]: core::f32::INFINITY /// [`NEG_INFINITY`]: core::f32::NEG_INFINITY -#[derive(Deref, Default, Debug, Copy, Clone, Display, PartialOrd)] +#[derive(AsRef, Deref, Default, Debug, Copy, Clone, Display, PartialOrd)] pub struct Float(f32); impl Float { @@ -25,16 +25,15 @@ impl Float { /// # Examples /// /// ``` - /// use hls_m3u8::types::Float; - /// + /// # use hls_m3u8::types::Float; /// let float = Float::new(1.0); /// ``` /// /// This would panic: /// /// ```should_panic + /// # use hls_m3u8::types::Float; /// use core::f32::NAN; - /// use hls_m3u8::types::Float; /// /// let float = Float::new(NAN); /// ``` @@ -53,6 +52,13 @@ impl Float { } /// Returns the underlying [`f32`]. + /// + /// # Example + /// + /// ``` + /// # use hls_m3u8::types::Float; + /// assert_eq!(Float::new(1.1_f32).as_f32(), 1.1_f32); + /// ``` pub const fn as_f32(self) -> f32 { self.0 } } diff --git a/src/types/ufloat.rs b/src/types/ufloat.rs index eb18e00..36da75a 100644 --- a/src/types/ufloat.rs +++ b/src/types/ufloat.rs @@ -2,18 +2,18 @@ use core::cmp::Ordering; use core::convert::TryFrom; use core::str::FromStr; -use derive_more::{Deref, Display}; +use derive_more::{AsRef, Deref, Display}; use crate::Error; -/// This is a wrapper type around an [`f32`] that can not be constructed -/// with a negative float (ex. `-1.1`), [`NaN`], [`INFINITY`] or +/// A wrapper type around an [`f32`], that can not be constructed +/// with a negative float (e.g. `-1.1`), [`NaN`], [`INFINITY`] or /// [`NEG_INFINITY`]. /// /// [`NaN`]: core::f32::NAN /// [`INFINITY`]: core::f32::INFINITY /// [`NEG_INFINITY`]: core::f32::NEG_INFINITY -#[derive(Deref, Default, Debug, Copy, Clone, PartialOrd, Display)] +#[derive(AsRef, Deref, Default, Debug, Copy, Clone, PartialOrd, Display)] pub struct UFloat(f32); impl UFloat { @@ -26,16 +26,14 @@ impl UFloat { /// # Examples /// /// ``` - /// use hls_m3u8::types::UFloat; - /// + /// # use hls_m3u8::types::UFloat; /// let float = UFloat::new(1.0); /// ``` /// /// This would panic: /// /// ```should_panic - /// use hls_m3u8::types::UFloat; - /// + /// # use hls_m3u8::types::UFloat; /// let float = UFloat::new(-1.0); /// ``` /// @@ -57,6 +55,13 @@ impl UFloat { } /// Returns the underlying [`f32`]. + /// + /// # Example + /// + /// ``` + /// # use hls_m3u8::types::UFloat; + /// assert_eq!(UFloat::new(1.1_f32).as_f32(), 1.1_f32); + /// ``` pub const fn as_f32(self) -> f32 { self.0 } }