1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/// Euclid operations on integers.
pub trait IntEuclidOps: Sized {
/// Checked Euclidean division. Computes `self.div_euclid(rhs)`,
/// returning `None` if `rhs == 0` or the division results in overflow.
fn checked_div_euclid(self, rhs: Self) -> Option<Self>;
/// Checked Euclidean remainder. Computes `self.rem_euclid(rhs)`, returning `None`
/// if `rhs == 0` or the division results in overflow.
fn checked_rem_euclid(self, rhs: Self) -> Option<Self>;
/// Wrapping Euclidean division. Computes `self.div_euclid(rhs)`,
/// wrapping around at the boundary of the type.
///
/// Wrapping will only occur in `MIN / -1` on a signed type (where `MIN` is the negative minimal value
/// for the type). This is equivalent to `-MIN`, a positive value that is too large to represent in the
/// type. In this case, this method returns `MIN` itself.
///
/// # Panics
///
/// This function will panic if `rhs` is 0.
fn wrapping_div_euclid(self, rhs: Self) -> Self;
/// Wrapping Euclidean remainder. Computes `self.rem_euclid(rhs)`, wrapping around
/// at the boundary of the type.
///
/// Wrapping will only occur in `MIN % -1` on a signed type (where `MIN` is the negative minimal value
/// for the type). In this case, this method returns 0.
///
/// # Panics
///
/// This function will panic if `rhs` is 0.
fn wrapping_rem_euclid(self, rhs: Self) -> Self;
/// Calculates the quotient of Euclidean division `self.div_euclid(rhs)`.
///
/// Returns a tuple of the divisor along with a boolean indicating whether an arithmetic overflow would
/// occur. If an overflow would occur then `self` is returned.
///
/// # Panics
///
/// This function will panic if `rhs` is 0.
fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool);
/// Overflowing Euclidean remainder. Calculates `self.rem_euclid(rhs)`.
///
/// Returns a tuple of the remainder after dividing along with a boolean indicating whether an
/// arithmetic overflow would occur. If an overflow would occur then 0 is returned.
///
/// # Panics
///
/// This function will panic if `rhs` is 0.
fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool);
}
/// Implements [`IntEuclidOps`].
macro_rules! impl_int_euclid {
($($t:ty),*) => {
$(impl IntEuclidOps for $t {
#[inline] fn checked_div_euclid(self, rhs: Self) -> Option<Self> { self.checked_div(rhs) }
#[inline] fn checked_rem_euclid(self, rhs: Self) -> Option<Self> { self.checked_rem(rhs) }
#[inline] fn wrapping_div_euclid(self, rhs: Self) -> Self { self.wrapping_div(rhs) }
#[inline] fn wrapping_rem_euclid(self, rhs: Self) -> Self { self.wrapping_rem(rhs) }
#[inline] fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) { self.overflowing_div(rhs) }
#[inline] fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) { self.overflowing_rem(rhs) }
})*
};
}
impl_int_euclid!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);