pub trait NothingBetween {
fn nothing_between(&self, other: &Self) -> bool;
}
macro_rules! nothing_between_for_int {
($t:tt) => {
impl NothingBetween for $t {
fn nothing_between(&self, other: &Self) -> bool {
other - self <= 1
}
}
};
}
nothing_between_for_int!(u8);
nothing_between_for_int!(u16);
nothing_between_for_int!(u32);
nothing_between_for_int!(u64);
nothing_between_for_int!(u128);
nothing_between_for_int!(i8);
nothing_between_for_int!(i16);
nothing_between_for_int!(i32);
nothing_between_for_int!(i64);
nothing_between_for_int!(i128);
nothing_between_for_int!(usize);
nothing_between_for_int!(isize);
impl NothingBetween for f32 {
fn nothing_between(&self, other: &Self) -> bool {
self + f32::EPSILON >= *other
}
}
impl NothingBetween for f64 {
fn nothing_between(&self, other: &Self) -> bool {
self + f64::EPSILON >= *other
}
}
impl NothingBetween for char {
fn nothing_between(&self, other: &Self) -> bool {
(*other as u32) - (*self as u32) <= 1
}
}
#[cfg(feature = "std")]
impl NothingBetween for std::time::Duration {
fn nothing_between(&self, other: &Self) -> bool {
other.as_nanos() - self.as_nanos() <= 1
}
}
impl<T: NothingBetween> NothingBetween for &T {
fn nothing_between(&self, other: &Self) -> bool {
(*self).nothing_between(*other)
}
}