From 4707482970336881753b48fe2a0760bd41e7cffe Mon Sep 17 00:00:00 2001 From: Trevor Spiteri Date: Thu, 4 Mar 2021 13:59:01 +0100 Subject: [PATCH] make Sum and Product supertraits of Fixed --- README.md | 4 ++++ RELEASES.md | 4 ++++ src/traits.rs | 20 ++++++++++++++------ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 188875b..a3deaef 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,8 @@ The conversions supported cover the following cases. [`from_ne_bytes`][f-fnb-1-7] * [`to_be_bytes`][f-tbb-1-7], [`to_le_bytes`][f-tlb-1-7], [`to_ne_bytes`][f-tnb-1-7] + * [`Sum`] and [`Product`] are now supertraits of the + [`Fixed`][tf-1-7] trait. * The [`F128Bits`][f128-1-7] type was added to support conversions and comparisons between fixed-point numbers and *binary128* floating-point numbers. @@ -111,6 +113,8 @@ The conversions supported cover the following cases. * [`OverflowingAdd`][nt-0-2-oa], [`OverflowingSub`][nt-0-2-os], [`OverflowingMul`][nt-0-2-om] +[`Product`]: https://doc.rust-lang.org/nightly/core/iter/trait.Product.html +[`Sum`]: https://doc.rust-lang.org/nightly/core/iter/trait.Sum.html [f-cnpot-1-7]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedU32.html#method.checked_next_power_of_two [f-fb-1-7]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.from_be [f-fbb-1-7]: https://tspiteri.gitlab.io/fixed/dev/fixed/struct.FixedI32.html#method.from_be_bytes diff --git a/RELEASES.md b/RELEASES.md index f94ca4f..26248fa 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -26,6 +26,8 @@ Version 1.7.0 (unreleased) [`from_ne_bytes`][f-fnb-1-7] * [`to_be_bytes`][f-tbb-1-7], [`to_le_bytes`][f-tlb-1-7], [`to_ne_bytes`][f-tnb-1-7] + * [`Sum`] and [`Product`] are now supertraits of the + [`Fixed`][tf-1-7] trait. * The [`F128Bits`][f128-1-7] type was added to support conversions and comparisons between fixed-point numbers and *binary128* floating-point numbers. @@ -577,3 +579,5 @@ Version 0.1.0 (2018-08-10) [*az* crate]: https://crates.io/crates/az [`MulAssign`]: https://doc.rust-lang.org/nightly/core/ops/trait.MulAssign.html +[`Product`]: https://doc.rust-lang.org/nightly/core/iter/trait.Product.html +[`Sum`]: https://doc.rust-lang.org/nightly/core/iter/trait.Sum.html diff --git a/src/traits.rs b/src/traits.rs index 2ba62a1..d3f88ba 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -26,6 +26,7 @@ use crate::{ use core::{ fmt::{Binary, Debug, Display, LowerHex, Octal, UpperHex}, hash::Hash, + iter::{Product, Sum}, mem, ops::{ Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, @@ -310,21 +311,28 @@ where Self: Debug + Display + Binary + Octal + LowerHex + UpperHex, Self: FromStr, Self: FromFixed + ToFixed, - Self: Add + AddAssign + Sub + SubAssign, - Self: Mul + MulAssign + Div + DivAssign, + Self: Add + AddAssign, + Self: Sub + SubAssign, + Self: Mul + MulAssign, + Self: Div + DivAssign, Self: Rem + RemAssign, Self: Mul<::Bits, Output = Self> + MulAssign<::Bits>, Self: Div<::Bits, Output = Self> + DivAssign<::Bits>, Self: Rem<::Bits, Output = Self> + RemAssign<::Bits>, - Self: Not + BitAnd + BitAndAssign, - Self: BitOr + BitOrAssign + BitXor + BitXorAssign, - Self: Shl + ShlAssign + Shr + ShrAssign, + Self: Not, + Self: BitAnd + BitAndAssign, + Self: BitOr + BitOrAssign, + Self: BitXor + BitXorAssign, + Self: Shl + ShlAssign, + Self: Shr + ShrAssign, + Self: Sum + Product, Self: PartialOrd + PartialOrd + PartialOrd, Self: PartialOrd + PartialOrd + PartialOrd, Self: PartialOrd + PartialOrd + PartialOrd, Self: PartialOrd + PartialOrd + PartialOrd, Self: PartialOrd + PartialOrd, - Self: PartialOrd + PartialOrd + PartialOrd, + Self: PartialOrd + PartialOrd, + Self: PartialOrd, Self: FixedOptionalFeatures, Self: Sealed, {