Skip to content

Commit b01e8bb

Browse files
authored
Expand Integer trait (#435)
Adds a number of new traits to the bounds including `Add`, `Sub`, and `Mul`, and expands HRTB coverage so that every trait which doesn't implicitly use `&Rhs` is covered for both owned and reference forms.
1 parent a4c3596 commit b01e8bb

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/traits.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ pub use num_traits::{
77
use crate::{Limb, NonZero};
88
use core::fmt::Debug;
99
use core::ops::{
10-
BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign, Not, Rem, Shl,
11-
ShlAssign, Shr, ShrAssign,
10+
Add, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign, Mul, Not,
11+
Rem, Shl, ShlAssign, Shr, ShrAssign, Sub,
1212
};
1313
use subtle::{
1414
Choice, ConditionallySelectable, ConstantTimeEq, ConstantTimeGreater, ConstantTimeLess,
@@ -30,16 +30,21 @@ pub trait Bounded {
3030
/// Integer trait: represents common functionality of integer types provided by this crate.
3131
pub trait Integer:
3232
'static
33-
+ AddMod
33+
+ Add<Output = Self>
34+
+ for<'a> Add<&'a Self, Output = Self>
35+
+ AddMod<Output = Self>
3436
+ AsRef<[Limb]>
35-
+ BitAndAssign
36-
+ BitOrAssign
37-
+ BitXorAssign
3837
+ BitAnd<Output = Self>
39-
+ BitOr<Output = Self>
40-
+ BitXor<Output = Self>
38+
+ for<'a> BitAnd<&'a Self, Output = Self>
39+
+ BitAndAssign
4140
+ for<'a> BitAndAssign<&'a Self>
41+
+ BitOr<Output = Self>
42+
+ for<'a> BitOr<&'a Self, Output = Self>
43+
+ BitOrAssign
4244
+ for<'a> BitOrAssign<&'a Self>
45+
+ BitXor<Output = Self>
46+
+ for<'a> BitXor<&'a Self, Output = Self>
47+
+ BitXorAssign
4348
+ for<'a> BitXorAssign<&'a Self>
4449
+ CheckedAdd
4550
+ CheckedSub
@@ -53,17 +58,19 @@ pub trait Integer:
5358
+ Debug
5459
+ Default
5560
+ Div<NonZero<Self>, Output = Self>
56-
+ DivAssign<NonZero<Self>>
5761
+ for<'a> Div<&'a NonZero<Self>, Output = Self>
62+
+ DivAssign<NonZero<Self>>
5863
+ for<'a> DivAssign<&'a NonZero<Self>>
5964
+ Eq
6065
+ From<u8>
6166
+ From<u16>
6267
+ From<u32>
6368
+ From<u64>
64-
+ MulMod
65-
+ NegMod
66-
+ Not
69+
+ Mul<Output = Self>
70+
+ for<'a> Mul<&'a Self, Output = Self>
71+
+ MulMod<Output = Self>
72+
+ NegMod<Output = Self>
73+
+ Not<Output = Self>
6774
+ Ord
6875
+ Rem<NonZero<Self>, Output = Self>
6976
+ for<'a> Rem<&'a NonZero<Self>, Output = Self>
@@ -73,7 +80,9 @@ pub trait Integer:
7380
+ ShlAssign<u32>
7481
+ Shr<u32, Output = Self>
7582
+ ShrAssign<u32>
76-
+ SubMod
83+
+ Sub<Output = Self>
84+
+ for<'a> Sub<&'a Self, Output = Self>
85+
+ SubMod<Output = Self>
7786
+ Sync
7887
+ WrappingAdd
7988
+ WrappingSub
@@ -345,7 +354,7 @@ pub trait Encoding: Sized {
345354
/// Support for optimized squaring
346355
pub trait Square: Sized
347356
where
348-
for<'a> &'a Self: core::ops::Mul<&'a Self, Output = Self>,
357+
for<'a> &'a Self: Mul<&'a Self, Output = Self>,
349358
{
350359
/// Computes the same as `self.mul(self)`, but may be more efficient.
351360
fn square(&self) -> Self {

0 commit comments

Comments
 (0)