//integer units #[derive(Clone,Copy,Hash,Eq,PartialEq,PartialOrd,Debug)] pub struct Time(i64); impl Time{ pub const ZERO:Self=Self(0); pub const ONE_SECOND:Self=Self(1_000_000_000); pub const ONE_MILLISECOND:Self=Self(1_000_000); pub const ONE_MICROSECOND:Self=Self(1_000); pub const ONE_NANOSECOND:Self=Self(1); #[inline] pub fn from_secs(num:i64)->Self{ Self(Self::ONE_SECOND.0*num) } #[inline] pub fn from_millis(num:i64)->Self{ Self(Self::ONE_MILLISECOND.0*num) } #[inline] pub fn from_micros(num:i64)->Self{ Self(Self::ONE_MICROSECOND.0*num) } #[inline] pub fn from_nanos(num:i64)->Self{ Self(Self::ONE_NANOSECOND.0*num) } //should I have checked subtraction? force all time variables to be positive? #[inline] pub fn nanos(&self)->i64{ self.0 } } impl From for Time{ #[inline] fn from(value:Planar64)->Self{ Time((((value.0 as i128)*1_000_000_000)>>32) as i64) } } impl std::fmt::Display for Time{ #[inline] fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{ write!(f,"{}s+{:09}ns",self.0/Self::ONE_SECOND.0,self.0%Self::ONE_SECOND.0) } } impl std::default::Default for Time{ fn default()->Self{ Self(0) } } impl std::ops::Neg for Time{ type Output=Time; #[inline] fn neg(self)->Self::Output { Time(-self.0) } } impl std::ops::Add