#[repr(transparent)]
#[derive(Debug, Default, Clone, Copy)]
pub(crate) struct Delta(u64);
impl Delta {
#[inline(always)]
#[must_use]
pub fn add(self, other: Self) -> Self {
self.0.wrapping_add(other.0).into()
}
#[inline(always)]
#[must_use]
pub fn sat_add(self, other: Self) -> Self {
self.0.saturating_add(other.0).into()
}
}
impl From<()> for Delta {
#[inline(always)]
fn from(_t: ()) -> Self {
Self(0)
}
}
impl From<Delta> for () {
#[inline(always)]
fn from(_v: Delta) -> Self {}
}
macro_rules! to_from_value {
{$t:ty} => {
impl From<Delta> for $t {
#[inline(always)]
fn from(v: Delta) -> Self {
v.0 as $t
}
}
impl From<$t> for Delta {
#[inline(always)]
fn from(t: $t) -> Self {
Delta(t as u64)
}
}
}
}
to_from_value!(u8);
to_from_value!(u16);
to_from_value!(u32);
to_from_value!(u64);
to_from_value!(u128);
to_from_value!(usize);
to_from_value!(f32);
to_from_value!(f64);