From e338e4bb76c88df6a019ed25a4c008fa1e26fbb8 Mon Sep 17 00:00:00 2001 From: z33ky <1zeeky@gmail.com> Date: Sat, 22 Jun 2024 08:54:10 +0000 Subject: [PATCH] Rename Closed* to Closed*Assign and introduce non-Assign Closed* traits (#5) --- src/scalar/field.rs | 31 ++++++++++++++++++++++++------- src/scalar/mod.rs | 5 ++++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/scalar/field.rs b/src/scalar/field.rs index fe345df..94a98e3 100644 --- a/src/scalar/field.rs +++ b/src/scalar/field.rs @@ -2,20 +2,32 @@ use crate::simd::SimdValue; use num::NumAssign; pub use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Rem, Sub, SubAssign}; +/// Trait __alias__ for `Add` with result of type `Self`. +pub trait ClosedAdd: Sized + Add {} + +/// Trait __alias__ for `Sub` with result of type `Self`. +pub trait ClosedSub: Sized + Sub {} + +/// Trait __alias__ for `Mul` with result of type `Self`. +pub trait ClosedMul: Sized + Mul {} + +/// Trait __alias__ for `Div` with result of type `Self`. +pub trait ClosedDiv: Sized + Div {} + +/// Trait __alias__ for `Neg` with result of type `Self`. +pub trait ClosedNeg: Sized + Neg {} + /// Trait __alias__ for `Add` and `AddAssign` with result of type `Self`. -pub trait ClosedAdd: Sized + Add + AddAssign {} +pub trait ClosedAddAssign: ClosedAdd + AddAssign {} /// Trait __alias__ for `Sub` and `SubAssign` with result of type `Self`. -pub trait ClosedSub: Sized + Sub + SubAssign {} +pub trait ClosedSubAssign: ClosedSub + SubAssign {} /// Trait __alias__ for `Mul` and `MulAssign` with result of type `Self`. -pub trait ClosedMul: Sized + Mul + MulAssign {} +pub trait ClosedMulAssign: ClosedMul + MulAssign {} /// Trait __alias__ for `Div` and `DivAssign` with result of type `Self`. -pub trait ClosedDiv: Sized + Div + DivAssign {} - -/// Trait __alias__ for `Neg` with result of type `Self`. -pub trait ClosedNeg: Sized + Neg {} +pub trait ClosedDivAssign: ClosedDiv + DivAssign {} impl ClosedAdd for T where T: Add + AddAssign {} impl ClosedSub for T where T: Sub + SubAssign {} @@ -23,6 +35,11 @@ impl ClosedMul for T where T: Mul + MulAssig impl ClosedDiv for T where T: Div + DivAssign {} impl ClosedNeg for T where T: Neg {} +impl ClosedAddAssign for T where T: ClosedAdd + AddAssign {} +impl ClosedSubAssign for T where T: ClosedSub + SubAssign {} +impl ClosedMulAssign for T where T: ClosedMul + MulAssign {} +impl ClosedDivAssign for T where T: ClosedDiv + DivAssign {} + /// Trait implemented by fields, i.e., complex numbers and floats. pub trait Field: SimdValue + NumAssign + ClosedNeg {} diff --git a/src/scalar/mod.rs b/src/scalar/mod.rs index c7ad59f..e017176 100644 --- a/src/scalar/mod.rs +++ b/src/scalar/mod.rs @@ -1,7 +1,10 @@ //! Traits implemented by scalar, non-SIMD, types. pub use self::complex::ComplexField; -pub use self::field::{ClosedAdd, ClosedDiv, ClosedMul, ClosedNeg, ClosedSub, Field}; +pub use self::field::{ + ClosedAdd, ClosedAddAssign, ClosedDiv, ClosedDivAssign, ClosedMul, ClosedMulAssign, ClosedNeg, + ClosedSub, ClosedSubAssign, Field, +}; #[cfg(feature = "partial_fixed_point_support")] pub use self::fixed_impl::*; pub use self::real::RealField;