diff --git a/src/display.rs b/src/display.rs index 449af1d..4d8b39b 100644 --- a/src/display.rs +++ b/src/display.rs @@ -95,15 +95,12 @@ macro_rules! fmt_radix2_helper { fmt_radix2_helper! { u8 u16 u32 u64 u128 } -fn fmt_radix2_helper( +fn fmt_radix2_helper( frac_bits: u32, (is_neg, mut int, mut frac): (bool, F, F), radix: &dyn Radix2, fmt: &mut Formatter, -) -> FmtResult -where - F: FmtRadix2Helper, -{ +) -> FmtResult { let int_bits = F::NBITS - frac_bits; let digit_bits: u32 = radix.digit_bits(); // 128 binary digits, one radix point, one leading zero @@ -275,14 +272,11 @@ macro_rules! fmt_dec_helper { fmt_dec_helper! { u8 u16 u32 u64 u128 } -fn fmt_dec_helper( +fn fmt_dec_helper( frac_bits: u32, (is_neg, mut int, mut frac): (bool, F, F), fmt: &mut Formatter, -) -> FmtResult -where - F: FmtDecHelper, -{ +) -> FmtResult { let int_bits = F::NBITS - frac_bits; // 40 int digits // + 128 frac digits diff --git a/src/lib.rs b/src/lib.rs index 75e7d7f..ac19225 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -339,10 +339,7 @@ assert_eq!(two_point_75.to_string(), \"2.8\"); Frac: Unsigned + IsLessOrEqual<$Len, Output = True>, { #[inline] - fn hash(&self, state: &mut H) - where - H: Hasher, - { + fn hash(&self, state: &mut H) { self.to_bits().hash(state); } } diff --git a/src/macros_from_to.rs b/src/macros_from_to.rs index 5322f4a..4403acd 100644 --- a/src/macros_from_to.rs +++ b/src/macros_from_to.rs @@ -89,10 +89,7 @@ assert_eq!(Dst::from_fixed(src >> 4), Dst::from_bits(1)); [`wrapping_from_fixed`]: #method.wrapping_from_fixed "; #[inline] - pub fn from_fixed(val: F) -> $Fixed - where - F: Fixed, - { + pub fn from_fixed(val: F) -> $Fixed { SealedFixed::from_fixed(val) } ); @@ -127,10 +124,7 @@ assert_eq!((src >> 4u32).to_fixed::(), Dst::from_bits(1)); [`wrapping_to_fixed`]: #method.wrapping_to_fixed "; #[inline] - pub fn to_fixed(self) -> F - where - F: Fixed, - { + pub fn to_fixed(self) -> F { SealedFixed::from_fixed(self) } ); @@ -180,10 +174,7 @@ assert_eq!(Fix::from_int(", [`wrapping_from_int`]: #method.wrapping_from_int "; #[inline] - pub fn from_int(val: I) -> $Fixed - where - I: Int, - { + pub fn from_int(val: I) -> $Fixed { SealedInt::to_fixed(val) } ); @@ -236,10 +227,7 @@ assert_eq!(", [`wrapping_to_int`]: #method.wrapping_to_int "; #[inline] - pub fn to_int(self) -> I - where - I: Int, - { + pub fn to_int(self) -> I { SealedInt::from_fixed(self) } ); @@ -288,10 +276,7 @@ assert_eq!(Fix::from_float(", [finite]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_finite "; #[inline] - pub fn from_float(val: F) -> $Fixed - where - F: Float, - { + pub fn from_float(val: F) -> $Fixed { SealedFloat::to_fixed(val) } ); @@ -328,10 +313,7 @@ assert_eq!(max_fixed.to_float::(), std::f32::INFINITY); [`f32`]: https://doc.rust-lang.org/nightly/std/primitive.f32.html [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html "; - pub fn to_float(self) -> F - where - F: Float, - { + pub fn to_float(self) -> F { SealedFixed::to_float(self) } ); @@ -361,10 +343,7 @@ assert!(Dst::checked_from_fixed(too_large).is_none()); [`None`]: https://doc.rust-lang.org/nightly/std/option/enum.Option.html#variant.None "; #[inline] - pub fn checked_from_fixed(val: F) -> Option<$Fixed> - where - F: Fixed, - { + pub fn checked_from_fixed(val: F) -> Option<$Fixed> { SealedFixed::checked_from_fixed(val) } ); @@ -395,10 +374,7 @@ assert!(Src::max_value().checked_to_fixed::().is_none()); [`None`]: https://doc.rust-lang.org/nightly/std/option/enum.Option.html#variant.None "; #[inline] - pub fn checked_to_fixed(self) -> Option - where - F: Fixed, - { + pub fn checked_to_fixed(self) -> Option { SealedFixed::checked_from_fixed(self) } ); @@ -447,10 +423,7 @@ assert!(Fix::checked_from_int(too_small).is_none()); [`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html "; #[inline] - pub fn checked_from_int(val: I) -> Option<$Fixed> - where - I: Int, - { + pub fn checked_from_int(val: I) -> Option<$Fixed> { SealedInt::checked_to_fixed(val) } ); @@ -508,10 +481,7 @@ assert!(AllInt::", [`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html "; #[inline] - pub fn checked_to_int(self) -> Option - where - I: Int, - { + pub fn checked_to_int(self) -> Option { SealedInt::checked_from_fixed(self) } ); @@ -552,10 +522,7 @@ assert!(Fix::checked_from_float(std::f64::NAN).is_none()); [`f64`]: https://doc.rust-lang.org/nightly/std/primitive.f64.html "; #[inline] - pub fn checked_from_float(val: F) -> Option<$Fixed> - where - F: Float, - { + pub fn checked_from_float(val: F) -> Option<$Fixed> { SealedFloat::checked_to_fixed(val) } ); @@ -591,10 +558,7 @@ assert_eq!(Dst::saturating_from_fixed(too_small), Dst::min_value()); ``` "; #[inline] - pub fn saturating_from_fixed(val: F) -> $Fixed - where - F: Fixed, - { + pub fn saturating_from_fixed(val: F) -> $Fixed { SealedFixed::saturating_from_fixed(val) } ); @@ -623,10 +587,7 @@ assert_eq!(saturated, TooFewIntBits::max_value()); ``` "; #[inline] - pub fn saturating_to_fixed(self) -> F - where - F: Fixed, - { + pub fn saturating_to_fixed(self) -> F { SealedFixed::saturating_from_fixed(self) } ); @@ -674,10 +635,7 @@ assert_eq!(Fix::saturating_from_int(too_small), Fix::min_value()); [`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html "; #[inline] - pub fn saturating_from_int(val: I) -> $Fixed - where - I: Int, - { + pub fn saturating_from_int(val: I) -> $Fixed { SealedInt::saturating_to_fixed(val) } ); @@ -743,10 +701,7 @@ assert_eq!(", [`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html "; #[inline] - pub fn saturating_to_int(self) -> I - where - I: Int, - { + pub fn saturating_to_int(self) -> I { SealedInt::saturating_from_fixed(self) } ); @@ -785,10 +740,7 @@ assert_eq!(Fix::saturating_from_float(f64::NEG_INFINITY), Fix::min_value()); [NaN]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_nan "; #[inline] - pub fn saturating_from_float(val: F) -> $Fixed - where - F: Float, - { + pub fn saturating_from_float(val: F) -> $Fixed { SealedFloat::saturating_to_fixed(val) } ); @@ -825,10 +777,7 @@ assert_eq!(Dst::wrapping_from_fixed(too_large), wrapped); ``` "; #[inline] - pub fn wrapping_from_fixed(val: F) -> $Fixed - where - F: Fixed, - { + pub fn wrapping_from_fixed(val: F) -> $Fixed { SealedFixed::wrapping_from_fixed(val) } ); @@ -858,10 +807,7 @@ assert_eq!(Src::max_value().wrapping_to_fixed::(), wrapped); ``` "; #[inline] - pub fn wrapping_to_fixed(self) -> F - where - F: Fixed, - { + pub fn wrapping_to_fixed(self) -> F { SealedFixed::wrapping_from_fixed(self) } ); @@ -909,10 +855,7 @@ assert_eq!(Fix::wrapping_from_int(large), wrapped); [`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html "; #[inline] - pub fn wrapping_from_int(val: I) -> $Fixed - where - I: Int, - { + pub fn wrapping_from_int(val: I) -> $Fixed { SealedInt::wrapping_to_fixed(val) } ); @@ -978,10 +921,7 @@ assert_eq!(", [`usize`]: https://doc.rust-lang.org/nightly/std/primitive.usize.html "; #[inline] - pub fn wrapping_to_int(self) -> I - where - I: Int, - { + pub fn wrapping_to_int(self) -> I { SealedInt::wrapping_from_fixed(self) } ); @@ -1030,10 +970,7 @@ assert_eq!(Fix::wrapping_from_float(large), wrapped); [finite]: https://doc.rust-lang.org/nightly/std/primitive.f64.html#method.is_finite "; #[inline] - pub fn wrapping_from_float(val: F) -> $Fixed - where - F: Float, - { + pub fn wrapping_from_float(val: F) -> $Fixed { SealedFloat::wrapping_to_fixed(val) } ); @@ -1077,10 +1014,7 @@ assert_eq!(Dst::overflowing_from_fixed(too_large), (wrapped, true)); [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html "; #[inline] - pub fn overflowing_from_fixed(val: F) -> ($Fixed, bool) - where - F: Fixed, - { + pub fn overflowing_from_fixed(val: F) -> ($Fixed, bool) { SealedFixed::overflowing_from_fixed(val) } ); @@ -1114,10 +1048,7 @@ assert_eq!(Src::max_value().overflowing_to_fixed::(), (wrapped, t ``` "; #[inline] - pub fn overflowing_to_fixed(self) -> (F, bool) - where - F: Fixed, - { + pub fn overflowing_to_fixed(self) -> (F, bool) { SealedFixed::overflowing_from_fixed(self) } ); @@ -1170,10 +1101,7 @@ assert_eq!(Fix::overflowing_from_int(large), (wrapped, true)); [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html "; #[inline] - pub fn overflowing_from_int(val: I) -> ($Fixed, bool) - where - I: Int, - { + pub fn overflowing_from_int(val: I) -> ($Fixed, bool) { SealedInt::overflowing_to_fixed(val) } ); @@ -1239,10 +1167,7 @@ assert_eq!(does_not_fit.overflowing_to_int::<", [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html "; #[inline] - pub fn overflowing_to_int(self) -> (I, bool) - where - I: Int, - { + pub fn overflowing_to_int(self) -> (I, bool) { SealedInt::overflowing_from_fixed(self) } ); @@ -1296,10 +1221,7 @@ assert_eq!(Fix::overflowing_from_float(large), (wrapped, true)); [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html "; #[inline] - pub fn overflowing_from_float(val: F) -> ($Fixed, bool) - where - F: Float, - { + pub fn overflowing_from_float(val: F) -> ($Fixed, bool) { SealedFloat::overflowing_to_fixed(val) } ); diff --git a/src/sealed_fixed.rs b/src/sealed_fixed.rs index b10cb42..f9c2b70 100644 --- a/src/sealed_fixed.rs +++ b/src/sealed_fixed.rs @@ -48,49 +48,30 @@ pub trait SealedFixed: Copy + Debug + Default + Display + Eq + Hash + Ord { const INT_LSB: u128 = Self::INT_MASK ^ (Self::INT_MASK << 1); #[inline] - fn from_fixed(val: F) -> Self - where - F: Fixed, - { + fn from_fixed(val: F) -> Self { let (wrapped, overflow) = SealedFixed::overflowing_from_fixed(val); debug_assert!(!overflow, "{} overflows", val); let _ = overflow; wrapped } #[inline] - fn checked_from_fixed(val: F) -> Option - where - F: Fixed, - { + fn checked_from_fixed(val: F) -> Option { match SealedFixed::overflowing_from_fixed(val) { (_, true) => None, (wrapped, false) => Some(wrapped), } } - fn saturating_from_fixed(fixed: F) -> Self - where - F: Fixed; + fn saturating_from_fixed(fixed: F) -> Self; #[inline] - fn wrapping_from_fixed(val: F) -> Self - where - F: Fixed, - { + fn wrapping_from_fixed(val: F) -> Self { let (wrapped, _) = SealedFixed::overflowing_from_fixed(val); wrapped } - fn overflowing_from_fixed(fixed: F) -> (Self, bool) - where - F: Fixed; + fn overflowing_from_fixed(fixed: F) -> (Self, bool); - fn saturating_from_float(float: F) -> Self - where - F: SealedFloat; - fn overflowing_from_float(float: F) -> (Self, bool) - where - F: SealedFloat; - fn to_float(self) -> F - where - F: SealedFloat; + fn saturating_from_float(float: F) -> Self; + fn overflowing_from_float(float: F) -> (Self, bool); + fn to_float(self) -> F; fn from_sbits(bits: Self::SBits) -> Self; fn to_sbits(self) -> Self::SBits; @@ -119,10 +100,7 @@ macro_rules! sealed_fixed { type SBits = $Bits; #[inline] - fn saturating_from_fixed(val: F) -> Self - where - F: Fixed, - { + fn saturating_from_fixed(val: F) -> Self { let (value, _, overflow) = val.to_sbits().to_fixed_dir_overflow( F::FRAC_NBITS as i32, Self::FRAC_NBITS, @@ -157,10 +135,7 @@ macro_rules! sealed_fixed { } #[inline] - fn overflowing_from_fixed(val: F) -> (Self, bool) - where - F: Fixed, - { + fn overflowing_from_fixed(val: F) -> (Self, bool) { let (value, _, mut overflow) = val.to_sbits().to_fixed_dir_overflow( F::FRAC_NBITS as i32, Self::FRAC_NBITS, @@ -189,10 +164,7 @@ macro_rules! sealed_fixed { } #[inline] - fn saturating_from_float(val: F) -> Self - where - F: SealedFloat, - { + fn saturating_from_float(val: F) -> Self { if val.is_nan() { panic!("NaN"); } @@ -228,10 +200,7 @@ macro_rules! sealed_fixed { $Fixed::from_bits(bits) } #[inline] - fn overflowing_from_float(val: F) -> (Self, bool) - where - F: SealedFloat, - { + fn overflowing_from_float(val: F) -> (Self, bool) { if !val.is_finite() { panic!("{} is not finite", val); } @@ -260,10 +229,7 @@ macro_rules! sealed_fixed { } #[inline] - fn to_float(self) -> F - where - F: SealedFloat, - { + fn to_float(self) -> F { let (neg, abs) = self.to_bits().neg_abs(); SealedFloat::from_neg_abs(neg, u128::from(abs), Self::FRAC_NBITS, Self::INT_NBITS) } diff --git a/src/sealed_float.rs b/src/sealed_float.rs index 69fbeda..2f7c95f 100644 --- a/src/sealed_float.rs +++ b/src/sealed_float.rs @@ -44,20 +44,14 @@ pub trait SealedFloat: Copy + Debug + Display { fn from_parts(sign: bool, exp: i32, mant: Self::Bits) -> Self; #[inline] - fn to_fixed(self) -> F - where - F: Fixed, - { + fn to_fixed(self) -> F { let (wrapped, overflow) = Self::overflowing_to_fixed(self); debug_assert!(!overflow, "{} overflows", self); let _ = overflow; wrapped } #[inline] - fn checked_to_fixed(self) -> Option - where - F: Fixed, - { + fn checked_to_fixed(self) -> Option { if !self.is_finite() { return None; } @@ -67,25 +61,16 @@ pub trait SealedFloat: Copy + Debug + Display { } } #[inline] - fn saturating_to_fixed(self) -> F - where - F: Fixed, - { + fn saturating_to_fixed(self) -> F { SealedFixed::saturating_from_float(self) } #[inline] - fn wrapping_to_fixed(self) -> F - where - F: Fixed, - { + fn wrapping_to_fixed(self) -> F { let (wrapped, _) = Self::overflowing_to_fixed(self); wrapped } #[inline] - fn overflowing_to_fixed(self) -> (F, bool) - where - F: Fixed, - { + fn overflowing_to_fixed(self) -> (F, bool) { SealedFixed::overflowing_from_float(self) } diff --git a/src/sealed_int.rs b/src/sealed_int.rs index 65474bf..5bacdb0 100644 --- a/src/sealed_int.rs +++ b/src/sealed_int.rs @@ -35,74 +35,48 @@ pub trait SealedInt: Copy + Ord + Debug + Display { const MSB: Self; #[inline] - fn from_fixed(val: F) -> Self - where - F: Fixed, - { + fn from_fixed(val: F) -> Self { let (wrapped, overflow) = Self::overflowing_from_fixed(val); debug_assert!(!overflow, "{} overflows", val); let _ = overflow; wrapped } #[inline] - fn checked_from_fixed(val: F) -> Option - where - F: Fixed, - { + fn checked_from_fixed(val: F) -> Option { match Self::overflowing_from_fixed(val) { (_, true) => None, (wrapped, false) => Some(wrapped), } } - fn saturating_from_fixed(val: F) -> Self - where - F: Fixed; + fn saturating_from_fixed(val: F) -> Self; #[inline] - fn wrapping_from_fixed(val: F) -> Self - where - F: Fixed, - { + fn wrapping_from_fixed(val: F) -> Self { let (wrapped, _) = Self::overflowing_from_fixed(val); wrapped } - fn overflowing_from_fixed(val: F) -> (Self, bool) - where - F: Fixed; + fn overflowing_from_fixed(val: F) -> (Self, bool); #[inline] - fn to_fixed(self) -> F - where - F: Fixed, - { + fn to_fixed(self) -> F { let (wrapped, overflow) = Self::overflowing_to_fixed(self); debug_assert!(!overflow, "{} overflows", self); let _ = overflow; wrapped } #[inline] - fn checked_to_fixed(self) -> Option - where - F: Fixed, - { + fn checked_to_fixed(self) -> Option { match Self::overflowing_to_fixed(self) { (_, true) => None, (wrapped, false) => Some(wrapped), } } - fn saturating_to_fixed(self) -> F - where - F: Fixed; + fn saturating_to_fixed(self) -> F; #[inline] - fn wrapping_to_fixed(self) -> F - where - F: Fixed, - { + fn wrapping_to_fixed(self) -> F { let (wrapped, _) = Self::overflowing_to_fixed(self); wrapped } - fn overflowing_to_fixed(self) -> (F, bool) - where - F: Fixed; + fn overflowing_to_fixed(self) -> (F, bool); fn min_value() -> Self; fn max_value() -> Self; @@ -146,34 +120,22 @@ macro_rules! sealed_int { } #[inline] - fn saturating_from_fixed(val: F) -> Self - where - F: Fixed, - { + fn saturating_from_fixed(val: F) -> Self { let saturated = Self::ReprFixed::saturating_from_fixed(val); IntRepr::from_int_repr(saturated.to_bits()) } #[inline] - fn overflowing_from_fixed(val: F) -> (Self, bool) - where - F: Fixed, - { + fn overflowing_from_fixed(val: F) -> (Self, bool) { let (wrapped, overflow) = Self::ReprFixed::overflowing_from_fixed(val); (IntRepr::from_int_repr(wrapped.to_bits()), overflow) } #[inline] - fn saturating_to_fixed(self) -> F - where - F: Fixed, - { + fn saturating_to_fixed(self) -> F { SealedFixed::saturating_from_fixed(self.to_repr_fixed()) } #[inline] - fn overflowing_to_fixed(self) -> (F, bool) - where - F: Fixed - { + fn overflowing_to_fixed(self) -> (F, bool) { SealedFixed::overflowing_from_fixed(self.to_repr_fixed()) } diff --git a/src/serdeize.rs b/src/serdeize.rs index 30e6b52..1791a5f 100644 --- a/src/serdeize.rs +++ b/src/serdeize.rs @@ -30,10 +30,7 @@ macro_rules! serde_fixed { where Frac: Unsigned + IsLessOrEqual<$NBits, Output = True>, { - fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { + fn serialize(&self, serializer: S) -> Result { let bits = self.to_bits(); let mut state = serializer.serialize_struct($Name, 1)?; state.serialize_field("bits", &bits)?; @@ -45,10 +42,7 @@ macro_rules! serde_fixed { where Frac: Unsigned + IsLessOrEqual<$NBits, Output = True>, { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { + fn deserialize>(deserializer: D) -> Result { struct FixedVisitor; impl<'de> Visitor<'de> for FixedVisitor { @@ -59,20 +53,14 @@ macro_rules! serde_fixed { formatter.write_str($Name) } - fn visit_seq(self, mut seq: V) -> Result<$TBits, V::Error> - where - V: SeqAccess<'de>, - { + fn visit_seq>(self, mut seq: V) -> Result<$TBits, V::Error> { let bits = seq .next_element()? .ok_or_else(|| de::Error::invalid_length(0, &self))?; Ok(bits) } - fn visit_map(self, mut map: V) -> Result<$TBits, V::Error> - where - V: MapAccess<'de>, - { + fn visit_map>(self, mut map: V) -> Result<$TBits, V::Error> { let mut bits = None; while let Some(key) = map.next_key()? { match key { @@ -114,10 +102,7 @@ enum Field { } impl<'de> Deserialize<'de> for Field { - fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { + fn deserialize>(deserializer: D) -> Result { struct FieldVisitor; impl<'de> Visitor<'de> for FieldVisitor { @@ -127,10 +112,7 @@ impl<'de> Deserialize<'de> for Field { formatter.write_str("`bits`") } - fn visit_str(self, value: &str) -> Result - where - E: de::Error, - { + fn visit_str(self, value: &str) -> Result { match value { "bits" => Ok(Field::Bits), _ => Err(de::Error::unknown_field(value, FIELDS)), diff --git a/src/traits.rs b/src/traits.rs index 728a82a..d29e504 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -655,33 +655,26 @@ pub trait FromFixed { /// [`wrapping_from_fixed`] instead. /// /// [`wrapping_from_fixed`]: #method.wrapping_from_fixed - fn from_fixed(val: F) -> Self - where - F: sealed::Fixed; + fn from_fixed(val: F) -> Self; /// Converts from a fixed-point number if it fits, otherwise returns [`None`]. /// /// Any extra fractional bits are truncated. /// /// [`None`]: https://doc.rust-lang.org/nightly/std/option/enum.Option.html#variant.None - fn checked_from_fixed(val: F) -> Option + fn checked_from_fixed(val: F) -> Option where - F: sealed::Fixed, Self: Sized; /// Converts from a fixed-point number, saturating if it does not fit. /// /// Any extra fractional bits are truncated. - fn saturating_from_fixed(val: F) -> Self - where - F: sealed::Fixed; + fn saturating_from_fixed(val: F) -> Self; /// Converts from a fixed-point number, wrapping if it does not fit. /// /// Any extra fractional bits are truncated. - fn wrapping_from_fixed(val: F) -> Self - where - F: sealed::Fixed; + fn wrapping_from_fixed(val: F) -> Self; /// Converts from a fixed-point number. /// @@ -693,9 +686,8 @@ pub trait FromFixed { /// /// [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html /// [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html - fn overflowing_from_fixed(val: F) -> (Self, bool) + fn overflowing_from_fixed(val: F) -> (Self, bool) where - F: sealed::Fixed, Self: Sized; } @@ -736,32 +728,24 @@ pub trait ToFixed { /// [`wrapping_to_fixed`] instead. /// /// [`wrapping_to_fixed`]: #method.wrapping_to_fixed - fn to_fixed(self) -> F - where - F: sealed::Fixed; + fn to_fixed(self) -> F; /// Converts to a fixed-point number if it fits, otherwise returns [`None`]. /// /// Any extra fractional bits are truncated. /// /// [`None`]: https://doc.rust-lang.org/nightly/std/option/enum.Option.html#variant.None - fn checked_to_fixed(self) -> Option - where - F: sealed::Fixed; + fn checked_to_fixed(self) -> Option; /// Converts to a fixed-point number, saturating if it does not fit. /// /// Any extra fractional bits are truncated. - fn saturating_to_fixed(self) -> F - where - F: sealed::Fixed; + fn saturating_to_fixed(self) -> F; /// Converts to a fixed-point number, wrapping if it does not fit. /// /// Any extra fractional bits are truncated. - fn wrapping_to_fixed(self) -> F - where - F: sealed::Fixed; + fn wrapping_to_fixed(self) -> F; /// Converts from a fixed-point number. /// @@ -773,45 +757,28 @@ pub trait ToFixed { /// /// [`bool`]: https://doc.rust-lang.org/nightly/std/primitive.bool.html /// [tuple]: https://doc.rust-lang.org/nightly/std/primitive.tuple.html - fn overflowing_to_fixed(self) -> (F, bool) - where - F: sealed::Fixed; + fn overflowing_to_fixed(self) -> (F, bool); } impl ToFixed for bool { #[inline] - fn to_fixed(self) -> F - where - F: sealed::Fixed, - { + fn to_fixed(self) -> F { ToFixed::to_fixed(u8::from(self)) } #[inline] - fn checked_to_fixed(self) -> Option - where - F: sealed::Fixed, - { + fn checked_to_fixed(self) -> Option { ToFixed::checked_to_fixed(u8::from(self)) } #[inline] - fn saturating_to_fixed(self) -> F - where - F: sealed::Fixed, - { + fn saturating_to_fixed(self) -> F { ToFixed::saturating_to_fixed(u8::from(self)) } #[inline] - fn wrapping_to_fixed(self) -> F - where - F: sealed::Fixed, - { + fn wrapping_to_fixed(self) -> F { ToFixed::wrapping_to_fixed(u8::from(self)) } #[inline] - fn overflowing_to_fixed(self) -> (F, bool) - where - F: sealed::Fixed, - { + fn overflowing_to_fixed(self) -> (F, bool) { ToFixed::overflowing_to_fixed(u8::from(self)) } } @@ -820,76 +787,46 @@ macro_rules! impl_int { ($Int:ident) => { impl FromFixed for $Int { #[inline] - fn from_fixed(val: F) -> Self - where - F: sealed::Fixed, - { + fn from_fixed(val: F) -> Self { SealedInt::from_fixed(val) } #[inline] - fn checked_from_fixed(val: F) -> Option - where - F: sealed::Fixed, - { + fn checked_from_fixed(val: F) -> Option { SealedInt::checked_from_fixed(val) } #[inline] - fn saturating_from_fixed(val: F) -> Self - where - F: sealed::Fixed, - { + fn saturating_from_fixed(val: F) -> Self { SealedInt::saturating_from_fixed(val) } #[inline] - fn wrapping_from_fixed(val: F) -> Self - where - F: sealed::Fixed, - { + fn wrapping_from_fixed(val: F) -> Self { SealedInt::wrapping_from_fixed(val) } #[inline] - fn overflowing_from_fixed(val: F) -> (Self, bool) - where - F: sealed::Fixed, - { + fn overflowing_from_fixed(val: F) -> (Self, bool) { SealedInt::overflowing_from_fixed(val) } } impl ToFixed for $Int { #[inline] - fn to_fixed(self) -> F - where - F: sealed::Fixed, - { + fn to_fixed(self) -> F { SealedInt::to_fixed(self) } #[inline] - fn checked_to_fixed(self) -> Option - where - F: sealed::Fixed, - { + fn checked_to_fixed(self) -> Option { SealedInt::checked_to_fixed(self) } #[inline] - fn saturating_to_fixed(self) -> F - where - F: sealed::Fixed, - { + fn saturating_to_fixed(self) -> F { SealedInt::saturating_to_fixed(self) } #[inline] - fn wrapping_to_fixed(self) -> F - where - F: sealed::Fixed, - { + fn wrapping_to_fixed(self) -> F { SealedInt::wrapping_to_fixed(self) } #[inline] - fn overflowing_to_fixed(self) -> (F, bool) - where - F: sealed::Fixed, - { + fn overflowing_to_fixed(self) -> (F, bool) { SealedInt::overflowing_to_fixed(self) } } @@ -913,76 +850,46 @@ macro_rules! impl_float { ($Float:ty) => { impl FromFixed for $Float { #[inline] - fn from_fixed(val: F) -> Self - where - F: sealed::Fixed, - { + fn from_fixed(val: F) -> Self { val.to_float() } #[inline] - fn checked_from_fixed(val: F) -> Option - where - F: sealed::Fixed, - { + fn checked_from_fixed(val: F) -> Option { Some(val.to_float()) } #[inline] - fn saturating_from_fixed(val: F) -> Self - where - F: sealed::Fixed, - { + fn saturating_from_fixed(val: F) -> Self { val.to_float() } #[inline] - fn wrapping_from_fixed(val: F) -> Self - where - F: sealed::Fixed, - { + fn wrapping_from_fixed(val: F) -> Self { val.to_float() } #[inline] - fn overflowing_from_fixed(val: F) -> (Self, bool) - where - F: sealed::Fixed, - { + fn overflowing_from_fixed(val: F) -> (Self, bool) { (val.to_float(), false) } } impl ToFixed for $Float { #[inline] - fn to_fixed(self) -> F - where - F: sealed::Fixed, - { + fn to_fixed(self) -> F { SealedFloat::to_fixed(self) } #[inline] - fn checked_to_fixed(self) -> Option - where - F: sealed::Fixed, - { + fn checked_to_fixed(self) -> Option { SealedFloat::checked_to_fixed(self) } #[inline] - fn saturating_to_fixed(self) -> F - where - F: sealed::Fixed, - { + fn saturating_to_fixed(self) -> F { SealedFloat::saturating_to_fixed(self) } #[inline] - fn wrapping_to_fixed(self) -> F - where - F: sealed::Fixed, - { + fn wrapping_to_fixed(self) -> F { SealedFloat::wrapping_to_fixed(self) } #[inline] - fn overflowing_to_fixed(self) -> (F, bool) - where - F: sealed::Fixed, - { + fn overflowing_to_fixed(self) -> (F, bool) { SealedFloat::overflowing_to_fixed(self) } } @@ -1110,38 +1017,23 @@ macro_rules! impl_fixed { Frac: Unsigned + IsLessOrEqual<$NBits, Output = True>, { #[inline] - fn from_fixed(val: F) -> Self - where - F: sealed::Fixed, - { + fn from_fixed(val: F) -> Self { SealedFixed::from_fixed(val) } #[inline] - fn checked_from_fixed(val: F) -> Option - where - F: sealed::Fixed, - { + fn checked_from_fixed(val: F) -> Option { SealedFixed::checked_from_fixed(val) } #[inline] - fn saturating_from_fixed(val: F) -> Self - where - F: sealed::Fixed, - { + fn saturating_from_fixed(val: F) -> Self { SealedFixed::saturating_from_fixed(val) } #[inline] - fn wrapping_from_fixed(val: F) -> Self - where - F: sealed::Fixed, - { + fn wrapping_from_fixed(val: F) -> Self { SealedFixed::wrapping_from_fixed(val) } #[inline] - fn overflowing_from_fixed(val: F) -> (Self, bool) - where - F: sealed::Fixed, - { + fn overflowing_from_fixed(val: F) -> (Self, bool) { SealedFixed::overflowing_from_fixed(val) } } @@ -1151,38 +1043,23 @@ macro_rules! impl_fixed { Frac: Unsigned + IsLessOrEqual<$NBits, Output = True>, { #[inline] - fn to_fixed(self) -> F - where - F: sealed::Fixed, - { + fn to_fixed(self) -> F { SealedFixed::from_fixed(self) } #[inline] - fn checked_to_fixed(self) -> Option - where - F: sealed::Fixed, - { + fn checked_to_fixed(self) -> Option { SealedFixed::checked_from_fixed(self) } #[inline] - fn saturating_to_fixed(self) -> F - where - F: sealed::Fixed, - { + fn saturating_to_fixed(self) -> F { SealedFixed::saturating_from_fixed(self) } #[inline] - fn wrapping_to_fixed(self) -> F - where - F: sealed::Fixed, - { + fn wrapping_to_fixed(self) -> F { SealedFixed::wrapping_from_fixed(self) } #[inline] - fn overflowing_to_fixed(self) -> (F, bool) - where - F: sealed::Fixed, - { + fn overflowing_to_fixed(self) -> (F, bool) { SealedFixed::overflowing_from_fixed(self) } } diff --git a/src/wrapping.rs b/src/wrapping.rs index f62ab43..d4c3250 100644 --- a/src/wrapping.rs +++ b/src/wrapping.rs @@ -48,14 +48,9 @@ use core::{ /// assert_eq!(Fix::min_value(), (max + delta).0); /// ``` #[repr(transparent)] -pub struct Wrapping(pub F) -where - F: Fixed; +pub struct Wrapping(pub F); -impl Wrapping -where - F: Fixed, -{ +impl Wrapping { /// Wrapping ceil. Rounds to the next integer towards +∞, wrapping /// on overflow. /// @@ -128,94 +123,64 @@ where } } -impl Clone for Wrapping -where - F: Fixed, -{ +impl Clone for Wrapping { #[inline] fn clone(&self) -> Wrapping { Wrapping(self.0) } } -impl Copy for Wrapping where F: Fixed {} +impl Copy for Wrapping {} -impl Default for Wrapping -where - F: Fixed, -{ +impl Default for Wrapping { #[inline] fn default() -> Wrapping { Wrapping(F::default()) } } -impl Hash for Wrapping -where - F: Fixed, -{ +impl Hash for Wrapping { #[inline] - fn hash(&self, state: &mut H) - where - H: Hasher, - { + fn hash(&self, state: &mut H) { (self.0).hash(state); } } -impl Debug for Wrapping -where - F: Fixed, -{ +impl Debug for Wrapping { #[inline] fn fmt(&self, f: &mut Formatter) -> FmtResult { ::fmt(&self.0, f) } } -impl Display for Wrapping -where - F: Fixed, -{ +impl Display for Wrapping { #[inline] fn fmt(&self, f: &mut Formatter) -> FmtResult { ::fmt(&self.0, f) } } -impl From for Wrapping -where - F: Fixed, -{ +impl From for Wrapping { #[inline] fn from(src: F) -> Wrapping { Wrapping(src) } } -impl Eq for Wrapping where F: Fixed {} -impl PartialEq> for Wrapping -where - F: Fixed, -{ +impl Eq for Wrapping {} +impl PartialEq> for Wrapping { #[inline] fn eq(&self, other: &Wrapping) -> bool { (self.0).eq(&other.0) } } -impl Ord for Wrapping -where - F: Fixed, -{ +impl Ord for Wrapping { #[inline] fn cmp(&self, other: &Wrapping) -> Ordering { (self.0).cmp(&other.0) } } -impl PartialOrd> for Wrapping -where - F: Fixed, -{ +impl PartialOrd> for Wrapping { #[inline] fn partial_cmp(&self, other: &Wrapping) -> Option { (self.0).partial_cmp(&other.0)