Skip to content

Commit 022f250

Browse files
authored
Merge pull request #332 from ocstl/master
Fix checked operations documentation.
2 parents b1f3bda + e8cb7b0 commit 022f250

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

src/ops/checked.rs

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use core::ops::{Add, Div, Mul, Rem, Shl, Shr, Sub};
22

3-
/// Performs addition that returns `None` instead of wrapping around on
4-
/// overflow.
3+
/// Performs addition, returning `None` if overflow occurred.
54
pub trait CheckedAdd: Sized + Add<Self, Output = Self> {
65
/// Adds two numbers, checking for overflow. If overflow happens, `None` is
76
/// returned.
@@ -33,9 +32,9 @@ checked_impl!(CheckedAdd, checked_add, i64);
3332
checked_impl!(CheckedAdd, checked_add, isize);
3433
checked_impl!(CheckedAdd, checked_add, i128);
3534

36-
/// Performs subtraction that returns `None` instead of wrapping around on underflow.
35+
/// Performs subtraction, returning `None` if overflow occurred.
3736
pub trait CheckedSub: Sized + Sub<Self, Output = Self> {
38-
/// Subtracts two numbers, checking for underflow. If underflow happens,
37+
/// Subtracts two numbers, checking for overflow. If overflow happens,
3938
/// `None` is returned.
4039
fn checked_sub(&self, v: &Self) -> Option<Self>;
4140
}
@@ -54,11 +53,10 @@ checked_impl!(CheckedSub, checked_sub, i64);
5453
checked_impl!(CheckedSub, checked_sub, isize);
5554
checked_impl!(CheckedSub, checked_sub, i128);
5655

57-
/// Performs multiplication that returns `None` instead of wrapping around on underflow or
58-
/// overflow.
56+
/// Performs multiplication, returning `None` if overflow occurred.
5957
pub trait CheckedMul: Sized + Mul<Self, Output = Self> {
60-
/// Multiplies two numbers, checking for underflow or overflow. If underflow
61-
/// or overflow happens, `None` is returned.
58+
/// Multiplies two numbers, checking for overflow. If overflow happens,
59+
/// `None` is returned.
6260
fn checked_mul(&self, v: &Self) -> Option<Self>;
6361
}
6462

@@ -76,10 +74,10 @@ checked_impl!(CheckedMul, checked_mul, i64);
7674
checked_impl!(CheckedMul, checked_mul, isize);
7775
checked_impl!(CheckedMul, checked_mul, i128);
7876

79-
/// Performs division that returns `None` instead of panicking on division by zero and instead of
80-
/// wrapping around on underflow and overflow.
77+
/// Performs division, returning `None` on division by zero or if overflow
78+
/// occurred.
8179
pub trait CheckedDiv: Sized + Div<Self, Output = Self> {
82-
/// Divides two numbers, checking for underflow, overflow and division by
80+
/// Divides two numbers, checking for overflow and division by
8381
/// zero. If any of that happens, `None` is returned.
8482
fn checked_div(&self, v: &Self) -> Option<Self>;
8583
}
@@ -98,11 +96,11 @@ checked_impl!(CheckedDiv, checked_div, i64);
9896
checked_impl!(CheckedDiv, checked_div, isize);
9997
checked_impl!(CheckedDiv, checked_div, i128);
10098

101-
/// Performs an integral remainder that returns `None` instead of panicking on division by zero and
102-
/// instead of wrapping around on underflow and overflow.
99+
/// Performs integral remainder, returning `None` on division by zero or if
100+
/// overflow occurred.
103101
pub trait CheckedRem: Sized + Rem<Self, Output = Self> {
104-
/// Finds the remainder of dividing two numbers, checking for underflow, overflow and division
105-
/// by zero. If any of that happens, `None` is returned.
102+
/// Finds the remainder of dividing two numbers, checking for overflow and
103+
/// division by zero. If any of that happens, `None` is returned.
106104
///
107105
/// # Examples
108106
///
@@ -148,7 +146,7 @@ macro_rules! checked_impl_unary {
148146
};
149147
}
150148

151-
/// Performs negation that returns `None` if the result can't be represented.
149+
/// Performs negation, returning `None` if the result can't be represented.
152150
pub trait CheckedNeg: Sized {
153151
/// Negates a number, returning `None` for results that can't be represented, like signed `MIN`
154152
/// values that can't be positive, or non-zero unsigned values that can't be negative.
@@ -183,8 +181,8 @@ checked_impl_unary!(CheckedNeg, checked_neg, i64);
183181
checked_impl_unary!(CheckedNeg, checked_neg, isize);
184182
checked_impl_unary!(CheckedNeg, checked_neg, i128);
185183

186-
/// Performs a left shift that returns `None` on shifts larger than
187-
/// or equal to the type width.
184+
/// Performs shift left, returning `None` on shifts larger than or equal to
185+
/// the type width.
188186
pub trait CheckedShl: Sized + Shl<u32, Output = Self> {
189187
/// Checked shift left. Computes `self << rhs`, returning `None`
190188
/// if `rhs` is larger than or equal to the number of bits in `self`.
@@ -227,8 +225,8 @@ checked_shift_impl!(CheckedShl, checked_shl, i64);
227225
checked_shift_impl!(CheckedShl, checked_shl, isize);
228226
checked_shift_impl!(CheckedShl, checked_shl, i128);
229227

230-
/// Performs a right shift that returns `None` on shifts larger than
231-
/// or equal to the type width.
228+
/// Performs shift right, returning `None` on shifts larger than or equal to
229+
/// the type width.
232230
pub trait CheckedShr: Sized + Shr<u32, Output = Self> {
233231
/// Checked shift right. Computes `self >> rhs`, returning `None`
234232
/// if `rhs` is larger than or equal to the number of bits in `self`.

src/ops/euclid.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,16 @@ impl Euclid for f64 {
136136
}
137137

138138
pub trait CheckedEuclid: Euclid {
139-
/// Performs euclid division that returns `None` instead of panicking on division by zero
140-
/// and instead of wrapping around on underflow and overflow.
139+
/// Performs euclid division, returning `None` on division by zero or if
140+
/// overflow occurred.
141141
fn checked_div_euclid(&self, v: &Self) -> Option<Self>;
142142

143-
/// Finds the euclid remainder of dividing two numbers, checking for underflow, overflow and
144-
/// division by zero. If any of that happens, `None` is returned.
143+
/// Finds the euclid remainder of dividing two numbers, returning `None` on
144+
/// division by zero or if overflow occurred.
145145
fn checked_rem_euclid(&self, v: &Self) -> Option<Self>;
146146

147-
/// Returns both the quotient and remainder from checked Euclidean division.
147+
/// Returns both the quotient and remainder from checked Euclidean division,
148+
/// returning `None` on division by zero or if overflow occurred.
148149
///
149150
/// By default, it internally calls both `CheckedEuclid::checked_div_euclid` and `CheckedEuclid::checked_rem_euclid`,
150151
/// but it can be overridden in order to implement some optimization.

0 commit comments

Comments
 (0)