From 2be8cfcd47614f1fa1bef7f059eab07c1f215fc4 Mon Sep 17 00:00:00 2001 From: Trevor Spiteri Date: Tue, 6 Apr 2021 14:30:37 +0200 Subject: [PATCH] doc reordering: ZERO before MIN and MAX --- src/macros_no_frac.rs | 28 ++++++++++++++-------------- src/traits.rs | 8 ++++---- src/unwrapped.rs | 20 ++++++++++---------- src/wrapping.rs | 20 ++++++++++---------- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/macros_no_frac.rs b/src/macros_no_frac.rs index 94f0a19..0490eb2 100644 --- a/src/macros_no_frac.rs +++ b/src/macros_no_frac.rs @@ -23,6 +23,20 @@ macro_rules! fixed_no_frac { /// The implementation of items in this block is independent /// of the number of fractional bits `Frac`. impl $Fixed { + comment! { + "Zero. + +# Examples + +```rust +use fixed::{types::extra::U4, ", $s_fixed, "}; +type Fix = ", $s_fixed, "; +assert_eq!(Fix::ZERO, Fix::from_bits(0)); +``` +"; + pub const ZERO: $Fixed = Self::from_bits(0); + } + comment! { "The smallest value that can be represented. @@ -51,20 +65,6 @@ assert_eq!(Fix::MAX, Fix::from_bits(", $s_inner, "::MAX)); pub const MAX: $Fixed = Self::from_bits(<$Inner>::MAX); } - comment! { - "Zero. - -# Examples - -```rust -use fixed::{types::extra::U4, ", $s_fixed, "}; -type Fix = ", $s_fixed, "; -assert_eq!(Fix::ZERO, Fix::from_bits(0)); -``` -"; - pub const ZERO: $Fixed = Self::from_bits(0); - } - comment! { "The smallest positive value that can be represented. diff --git a/src/traits.rs b/src/traits.rs index 729ab93..de3892b 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -301,15 +301,15 @@ where /// [U32]: crate::types::extra::Unsigned::U32 type Frac: Unsigned; + /// Zero. + const ZERO: Self; + /// The smallest value that can be represented. const MIN: Self; /// The largest value that can be represented. const MAX: Self; - /// Zero. - const ZERO: Self; - /// The smallest positive value that can be represented. const DELTA: Self; @@ -2257,9 +2257,9 @@ macro_rules! impl_fixed { type Bits = $Bits; type Bytes = [u8; mem::size_of::<$Bits>()]; type Frac = Frac; + const ZERO: Self = Self::ZERO; const MIN: Self = Self::MIN; const MAX: Self = Self::MAX; - const ZERO: Self = Self::ZERO; const DELTA: Self = Self::DELTA; const IS_SIGNED: bool = Self::IS_SIGNED; const INT_NBITS: u32 = Self::INT_NBITS; diff --git a/src/unwrapped.rs b/src/unwrapped.rs index ef3d79d..d24cba2 100644 --- a/src/unwrapped.rs +++ b/src/unwrapped.rs @@ -52,6 +52,16 @@ use core::{ pub struct Unwrapped(pub F); impl Unwrapped { + /// Zero. + /// + /// # Examples + /// + /// ```rust + /// use fixed::{types::I16F16, Unwrapped}; + /// assert_eq!(Unwrapped::::ZERO, Unwrapped(I16F16::ZERO)); + /// ``` + pub const ZERO: Unwrapped = Unwrapped(F::ZERO); + /// The smallest value that can be represented. /// /// # Examples @@ -72,16 +82,6 @@ impl Unwrapped { /// ``` pub const MAX: Unwrapped = Unwrapped(F::MAX); - /// Zero. - /// - /// # Examples - /// - /// ```rust - /// use fixed::{types::I16F16, Unwrapped}; - /// assert_eq!(Unwrapped::::ZERO, Unwrapped(I16F16::ZERO)); - /// ``` - pub const ZERO: Unwrapped = Unwrapped(F::ZERO); - /// The smallest positive value that can be represented. /// /// # Examples diff --git a/src/wrapping.rs b/src/wrapping.rs index 11c67b7..72f695d 100644 --- a/src/wrapping.rs +++ b/src/wrapping.rs @@ -49,6 +49,16 @@ use core::{ pub struct Wrapping(pub F); impl Wrapping { + /// Zero. + /// + /// # Examples + /// + /// ```rust + /// use fixed::{types::I16F16, Wrapping}; + /// assert_eq!(Wrapping::::ZERO, Wrapping(I16F16::ZERO)); + /// ``` + pub const ZERO: Wrapping = Wrapping(F::ZERO); + /// The smallest value that can be represented. /// /// # Examples @@ -69,16 +79,6 @@ impl Wrapping { /// ``` pub const MAX: Wrapping = Wrapping(F::MAX); - /// Zero. - /// - /// # Examples - /// - /// ```rust - /// use fixed::{types::I16F16, Wrapping}; - /// assert_eq!(Wrapping::::ZERO, Wrapping(I16F16::ZERO)); - /// ``` - pub const ZERO: Wrapping = Wrapping(F::ZERO); - /// The smallest positive value that can be represented. /// /// # Examples