third_party/rust/num-traits-0.1.39/src/ops/saturating.rs
author Andreas Tolfsen <ato@sny.no>
Fri, 03 Nov 2017 13:39:05 +0000
changeset 443335 257f99d6b09d6d9e3669c9472df3b4838fb906e7
parent 430380 third_party/rust/num-traits-0.1.37/src/ops/saturating.rs@a8ae266cd61eb004d4f74a989e4d9c6d2ceb5b93
permissions -rw-r--r--
Bug 1414254 - Vendor Rust dependencies r=jgraham MozReview-Commit-ID: CnT3DLl2KBR

/// Saturating math operations
pub trait Saturating {
    /// Saturating addition operator.
    /// Returns a+b, saturating at the numeric bounds instead of overflowing.
    fn saturating_add(self, v: Self) -> Self;

    /// Saturating subtraction operator.
    /// Returns a-b, saturating at the numeric bounds instead of overflowing.
    fn saturating_sub(self, v: Self) -> Self;
}

macro_rules! saturating_impl {
    ($trait_name:ident for $($t:ty)*) => {$(
        impl $trait_name for $t {
            #[inline]
            fn saturating_add(self, v: Self) -> Self {
                Self::saturating_add(self, v)
            }

            #[inline]
            fn saturating_sub(self, v: Self) -> Self {
                Self::saturating_sub(self, v)
            }
        }
    )*}
}

saturating_impl!(Saturating for isize usize i8 u8 i16 u16 i32 u32 i64 u64);