use std::fmt::Debug;
use std::any::Any;
use std::default::Default;
use std::fmt::Formatter;
use std::fmt::Error;
use order::PartialOrder;
use progress::nested::product::Product;
use abomonation::Abomonation;
pub trait Timestamp: Clone+Eq+PartialOrder+Default+Debug+Send+Any+Abomonation {
type Summary : PathSummary<Self> + 'static;
}
pub trait PathSummary<T> : Clone+'static+Eq+PartialOrder+Debug+Default {
fn results_in(&self, src: &T) -> Option<T>;
fn followed_by(&self, other: &Self) -> Option<Self>;
}
#[derive(Copy, Clone, Hash, Eq, Ord, PartialOrd, PartialEq, Default)]
pub struct RootTimestamp;
impl Timestamp for RootTimestamp { type Summary = RootSummary; }
impl Debug for RootTimestamp {
#[inline]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
f.write_str("Root")
}
}
impl PartialOrder for RootTimestamp { #[inline(always)] fn less_equal(&self, _other: &Self) -> bool { true } }
impl Abomonation for RootTimestamp { }
impl RootTimestamp {
#[inline]
pub fn new<T: Timestamp>(t: T) -> Product<RootTimestamp, T> {
Product::new(RootTimestamp, t)
}
}
#[derive(Copy, Clone, Eq, Ord, PartialOrd, PartialEq, Debug, Default)]
pub struct RootSummary;
impl PathSummary<RootTimestamp> for RootSummary {
#[inline]
fn results_in(&self, _: &RootTimestamp) -> Option<RootTimestamp> { Some(RootTimestamp) }
#[inline]
fn followed_by(&self, _: &RootSummary) -> Option<RootSummary> { Some(RootSummary) }
}
impl PartialOrder for RootSummary { #[inline(always)] fn less_equal(&self, _other: &Self) -> bool { true } }
impl Timestamp for () { type Summary = (); }
impl PathSummary<()> for () {
fn results_in(&self, _src: &()) -> Option<()> { Some(()) }
fn followed_by(&self, _other: &()) -> Option<()> { Some(()) }
}
impl Timestamp for usize { type Summary = usize; }
impl PathSummary<usize> for usize {
#[inline]
fn results_in(&self, src: &usize) -> Option<usize> { self.checked_add(*src) }
#[inline]
fn followed_by(&self, other: &usize) -> Option<usize> { self.checked_add(*other) }
}
impl Timestamp for u64 { type Summary = u64; }
impl PathSummary<u64> for u64 {
#[inline]
fn results_in(&self, src: &u64) -> Option<u64> { self.checked_add(*src) }
#[inline]
fn followed_by(&self, other: &u64) -> Option<u64> { self.checked_add(*other) }
}
impl Timestamp for u32 { type Summary = u32; }
impl PathSummary<u32> for u32 {
#[inline]
fn results_in(&self, src: &u32) -> Option<u32> { self.checked_add(*src) }
#[inline]
fn followed_by(&self, other: &u32) -> Option<u32> { self.checked_add(*other) }
}
impl Timestamp for i32 { type Summary = i32; }
impl PathSummary<i32> for i32 {
#[inline]
fn results_in(&self, src: &i32) -> Option<i32> { self.checked_add(*src) }
#[inline]
fn followed_by(&self, other: &i32) -> Option<i32> { self.checked_add(*other) }
}