xint/
lib.rs

1pub trait Xint {
2    /// Wrapping (modular) addition. Computes self + rhs, wrapping around at the boundary of the type.
3    fn wrapping_add(self, other: Self) -> Self;
4}
5
6#[macro_export]
7macro_rules! impl_xint_wrap {
8    ($name:ident, $uint:ty, $sint:ty) => {
9        #[derive(Clone, Copy, Default, PartialEq, Eq)]
10        pub struct $name(pub $uint);
11
12        impl Xint for $name {
13            fn wrapping_add(self, other: Self) -> Self {
14                Self(self.0.wrapping_add(other.0))
15            }
16        }
17    };
18}
19
20impl_xint_wrap!(X8, u8, i8);
21impl_xint_wrap!(X16, u16, i16);
22impl_xint_wrap!(X32, u32, i32);
23impl_xint_wrap!(X64, u64, i64);