use std::fmt; use std::ops::{Add, Sub, AddAssign, SubAssign, Mul, MulAssign, Div, DivAssign}; pub trait Internal: Copy + Clone + PartialEq + fmt::Debug + fmt::Display + PartialOrd + Add + Sub + AddAssign + SubAssign + Mul + MulAssign + Div + DivAssign + { const ZERO: Self; fn as_usize(&self) -> usize; fn as_f64(&self) -> f64; } macro_rules! impl_for_type { ($z:expr, $t:ty) => { impl Internal for $t { const ZERO: Self = $z; fn as_usize(&self) -> usize { *self as usize } fn as_f64(&self) -> f64 { *self as f64 } } }; } impl_for_type!(0, u8); impl_for_type!(0, u16); impl_for_type!(0, u32); impl_for_type!(0, u64); impl_for_type!(0, u128); impl_for_type!(0, usize); impl_for_type!(0, i8); impl_for_type!(0, i16); impl_for_type!(0, i32); impl_for_type!(0, i64); impl_for_type!(0, i128); impl_for_type!(0, isize); impl_for_type!(0.0, f32); impl_for_type!(0.0, f64);