use std::fmt::{Formatter, Error, Debug};
use order::PartialOrder;
use progress::Timestamp;
use progress::nested::summary::Summary;
use abomonation::Abomonation;
#[derive(Copy, Clone, Hash, Eq, PartialEq, Default, Ord, PartialOrd)]
pub struct Product<TOuter, TInner> {
pub outer: TOuter,
pub inner: TInner,
}
impl<TOuter, TInner> Product<TOuter, TInner> {
pub fn new(outer: TOuter, inner: TInner) -> Product<TOuter, TInner> {
Product {
outer: outer,
inner: inner,
}
}
}
impl<TOuter: Debug, TInner: Debug> Debug for Product<TOuter, TInner> {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
f.write_str(&format!("({:?}, {:?})", self.outer, self.inner))
}
}
impl<TOuter: PartialOrder, TInner: PartialOrder> PartialOrder for Product<TOuter, TInner> {
#[inline(always)]
fn less_equal(&self, other: &Self) -> bool {
self.outer.less_equal(&other.outer) && self.inner.less_equal(&other.inner)
}
}
impl<TOuter: Timestamp, TInner: Timestamp> Timestamp for Product<TOuter, TInner> {
type Summary = Summary<TOuter::Summary, TInner::Summary>;
}
impl<TOuter: Abomonation, TInner: Abomonation> Abomonation for Product<TOuter, TInner> {
unsafe fn embalm(&mut self) { self.outer.embalm(); self.inner.embalm(); }
unsafe fn entomb(&self, bytes: &mut Vec<u8>) { self.outer.entomb(bytes); self.inner.entomb(bytes); }
unsafe fn exhume<'a,'b>(&'a mut self, mut bytes: &'b mut [u8]) -> Option<&'b mut [u8]> {
let tmp = bytes; bytes = if let Some(bytes) = self.outer.exhume(tmp) { bytes } else { return None };
let tmp = bytes; bytes = if let Some(bytes) = self.inner.exhume(tmp) { bytes } else { return None };
Some(bytes)
}
}