remove formats
This commit is contained in:
parent
97f3892bd1
commit
f74de249c8
|
@ -1,4 +1,4 @@
|
||||||
use core::ops::{Add, Sub, Mul, Div, Shl, Shr};
|
use core::ops::{Add, Sub, Mul, Div, Rem, Shl, Shr};
|
||||||
|
|
||||||
/// Performs addition that returns `None` instead of wrapping around on
|
/// Performs addition that returns `None` instead of wrapping around on
|
||||||
/// overflow.
|
/// overflow.
|
||||||
|
@ -90,6 +90,51 @@ checked_impl!(CheckedDiv, checked_div, i32);
|
||||||
checked_impl!(CheckedDiv, checked_div, i64);
|
checked_impl!(CheckedDiv, checked_div, i64);
|
||||||
checked_impl!(CheckedDiv, checked_div, isize);
|
checked_impl!(CheckedDiv, checked_div, isize);
|
||||||
|
|
||||||
|
// CheckedRem
|
||||||
|
pub trait CheckedRem: Sized + Rem<Self, Output = Self> {
|
||||||
|
fn checked_rem(&self, v: &Self) -> Option<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
checked_impl!(CheckedRem, checked_rem, u8);
|
||||||
|
checked_impl!(CheckedRem, checked_rem, u16);
|
||||||
|
checked_impl!(CheckedRem, checked_rem, u32);
|
||||||
|
checked_impl!(CheckedRem, checked_rem, u64);
|
||||||
|
checked_impl!(CheckedRem, checked_rem, usize);
|
||||||
|
|
||||||
|
checked_impl!(CheckedRem, checked_rem, i8);
|
||||||
|
checked_impl!(CheckedRem, checked_rem, i16);
|
||||||
|
checked_impl!(CheckedRem, checked_rem, i32);
|
||||||
|
checked_impl!(CheckedRem, checked_rem, i64);
|
||||||
|
checked_impl!(CheckedRem, checked_rem, isize);
|
||||||
|
|
||||||
|
// CheckedNeg
|
||||||
|
macro_rules! checked_impl_one_para {
|
||||||
|
($trait_name:ident, $method:ident, $t:ty) => {
|
||||||
|
impl $trait_name for $t {
|
||||||
|
#[inline]
|
||||||
|
fn $method(&self) -> Option<$t> {
|
||||||
|
<$t>::$method(*self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub trait CheckedNeg: Sized {
|
||||||
|
fn checked_neg(&self) -> Option<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
checked_impl_one_para!(CheckedNeg, checked_neg, u8);
|
||||||
|
checked_impl_one_para!(CheckedNeg, checked_neg, u16);
|
||||||
|
checked_impl_one_para!(CheckedNeg, checked_neg, u32);
|
||||||
|
checked_impl_one_para!(CheckedNeg, checked_neg, u64);
|
||||||
|
checked_impl_one_para!(CheckedNeg, checked_neg, usize);
|
||||||
|
|
||||||
|
checked_impl_one_para!(CheckedNeg, checked_neg, i8);
|
||||||
|
checked_impl_one_para!(CheckedNeg, checked_neg, i16);
|
||||||
|
checked_impl_one_para!(CheckedNeg, checked_neg, i32);
|
||||||
|
checked_impl_one_para!(CheckedNeg, checked_neg, i64);
|
||||||
|
checked_impl_one_para!(CheckedNeg, checked_neg, isize);
|
||||||
|
|
||||||
/// Performs a left shift that returns `None` on overflow.
|
/// Performs a left shift that returns `None` on overflow.
|
||||||
pub trait CheckedShl: Sized + Shl<u32, Output=Self> {
|
pub trait CheckedShl: Sized + Shl<u32, Output=Self> {
|
||||||
/// Shifts a number to the left, checking for overflow. If overflow happens,
|
/// Shifts a number to the left, checking for overflow. If overflow happens,
|
||||||
|
|
Loading…
Reference in New Issue