pub trait DiscreteFinite {
fn min_value() -> Self;
fn max_value() -> Self;
fn up(&self) -> Option<Self>
where
Self: Sized;
fn down(&self) -> Option<Self>
where
Self: Sized;
}
macro_rules! foo {
() => {};
($ident:ident, $($t:tt)*) => {
impl DiscreteFinite for $ident {
fn min_value () -> Self { $ident::MIN }
fn max_value () -> Self { $ident::MAX }
fn up(&self) -> Option<Self> {
self.checked_add(1)
}
fn down(&self) -> Option<Self> {
self.checked_sub(1)
}
}
foo!($($t)*);
};
}
foo!(u8, i8, u16, i16, u32, i32, u64, i64, u128, i128, usize,);