aboutsummaryrefslogtreecommitdiff
path: root/src/v1_45.rs
blob: b18fb8dcafa9106f599449e2c821444f97e92f30 (plain)
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
use crate::traits::SignedInteger;
#[cfg(__standback_before_1_43)]
use crate::v1_43::int_v1_43;

pub trait int_v1_45: SignedInteger {
    fn saturating_neg(self) -> Self;
    fn saturating_abs(self) -> Self;
}

macro_rules! impl_int_v1_45 {
    ($($type:ty),*) => {$(
        impl int_v1_45 for $type {
            fn saturating_neg(self) -> Self {
                if self == Self::MIN {
                    Self::MAX
                } else {
                    -self
                }
            }

            fn saturating_abs(self) -> Self {
                if self.is_negative() {
                    self.saturating_neg()
                } else {
                    self
                }
            }
        }
    )*};
}

impl_int_v1_45![i8, i16, i32, i64, i128, isize];