Skip to content

Commit d51a67b

Browse files
Split integral traits into four subtraits
1 parent ce40d2a commit d51a67b

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/internal_type_traits.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,37 +52,65 @@ pub trait Integral:
5252
+ fmt::Debug
5353
+ fmt::Binary
5454
+ fmt::Octal
55+
+ Zero
56+
+ One
57+
+ BoundedBelow
58+
+ BoundedAbove
5559
{
60+
}
61+
62+
/// Class that has additive identity element
63+
pub trait Zero {
64+
/// The additive identity element
5665
fn zero() -> Self;
66+
}
67+
68+
/// Class that has multiplicative identity element
69+
pub trait One {
70+
/// The multiplicative identity element
5771
fn one() -> Self;
72+
}
73+
74+
pub trait BoundedBelow {
5875
fn min_value() -> Self;
76+
}
77+
78+
pub trait BoundedAbove {
5979
fn max_value() -> Self;
6080
}
6181

6282
macro_rules! impl_integral {
6383
($($ty:ty),*) => {
6484
$(
65-
impl Integral for $ty {
85+
impl Zero for $ty {
6686
#[inline]
6787
fn zero() -> Self {
6888
0
6989
}
90+
}
7091

92+
impl One for $ty {
7193
#[inline]
7294
fn one() -> Self {
7395
1
7496
}
97+
}
7598

99+
impl BoundedBelow for $ty {
76100
#[inline]
77101
fn min_value() -> Self {
78102
Self::min_value()
79103
}
104+
}
80105

106+
impl BoundedAbove for $ty {
81107
#[inline]
82108
fn max_value() -> Self {
83109
Self::max_value()
84110
}
85111
}
112+
113+
impl Integral for $ty {}
86114
)*
87115
};
88116
}

0 commit comments

Comments
 (0)