use std::fmt::Debug;
use std::any::Any;
use std::default::Default;
use crate::ExchangeData;
use crate::order::PartialOrder;
pub trait Timestamp: Clone+Eq+PartialOrder+Ord+Debug+Any+ExchangeData {
type Summary : PathSummary<Self> + 'static;
fn minimum() -> Self;
}
pub trait PathSummary<T> : Clone+Eq+PartialOrder+Debug+Default {
fn results_in(&self, src: &T) -> Option<T>;
fn followed_by(&self, other: &Self) -> Option<Self>;
}
impl Timestamp for () { type Summary = (); fn minimum() -> Self { }}
impl PathSummary<()> for () {
#[inline] fn results_in(&self, _src: &()) -> Option<()> { Some(()) }
#[inline] fn followed_by(&self, _other: &()) -> Option<()> { Some(()) }
}
macro_rules! implement_timestamp_add {
($($index_type:ty,)*) => (
$(
impl Timestamp for $index_type {
type Summary = $index_type;
fn minimum() -> Self { Self::MIN }
}
impl PathSummary<$index_type> for $index_type {
#[inline]
fn results_in(&self, src: &$index_type) -> Option<$index_type> { self.checked_add(*src) }
#[inline]
fn followed_by(&self, other: &$index_type) -> Option<$index_type> { self.checked_add(*other) }
}
)*
)
}
implement_timestamp_add!(usize, u128, u64, u32, u16, u8, isize, i128, i64, i32, i16, i8,);
impl Timestamp for ::std::time::Duration {
type Summary = ::std::time::Duration;
fn minimum() -> Self { ::std::time::Duration::new(0, 0) }
}
impl PathSummary<::std::time::Duration> for ::std::time::Duration {
#[inline]
fn results_in(&self, src: &::std::time::Duration) -> Option<::std::time::Duration> { self.checked_add(*src) }
#[inline]
fn followed_by(&self, other: &::std::time::Duration) -> Option<::std::time::Duration> { self.checked_add(*other) }
}
pub use self::refines::Refines;
mod refines {
use crate::progress::Timestamp;
pub trait Refines<T: Timestamp> : Timestamp {
fn to_inner(other: T) -> Self;
fn to_outer(self) -> T;
fn summarize(path: <Self as Timestamp>::Summary) -> <T as Timestamp>::Summary;
}
impl<T: Timestamp> Refines<T> for T {
fn to_inner(other: T) -> T { other }
fn to_outer(self) -> T { self }
fn summarize(path: <T as Timestamp>::Summary) -> <T as Timestamp>::Summary { path }
}
macro_rules! implement_refines_empty {
($($index_type:ty,)*) => (
$(
impl Refines<()> for $index_type {
fn to_inner(_: ()) -> $index_type { Default::default() }
fn to_outer(self) -> () { }
fn summarize(_: <$index_type as Timestamp>::Summary) -> () { }
}
)*
)
}
implement_refines_empty!(usize, u128, u64, u32, u16, u8, isize, i128, i64, i32, i16, i8, ::std::time::Duration,);
}