1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
use crate::TimeBounds; pub trait IntoTimePoint { fn into_time_point(self) -> u64; } pub struct MilliSecondEpochTime(pub u64); pub struct SecondEpochTime(pub u64); impl IntoTimePoint for MilliSecondEpochTime { fn into_time_point(self) -> u64 { self.0 / 1000 } } impl IntoTimePoint for SecondEpochTime { fn into_time_point(self) -> u64 { self.0 } } impl IntoTimePoint for () { fn into_time_point(self) -> u64 { 0 } } impl TimeBounds { pub fn from_time_points<T: IntoTimePoint, S: IntoTimePoint>( min_time: T, max_time: S, ) -> TimeBounds { TimeBounds { min_time: min_time.into_time_point(), max_time: max_time.into_time_point(), } } }