use crate::core::Timestamp;
use core::{fmt, ops, time::Duration};
use serde::{Deserialize, Serialize};
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Stamp {
pub acqtime: Acqtime,
pub pubtime: Pubtime,
}
impl fmt::Debug for Stamp {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(
fmt,
"Stamp {{ acq: {:?}, pub: {:?} }}",
*self.acqtime, *self.pubtime
)
}
}
pub trait TimestampMarker {
fn display_str_short() -> &'static str;
}
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct AcqtimeMarker;
impl TimestampMarker for AcqtimeMarker {
fn display_str_short() -> &'static str {
"AcqT"
}
}
pub type Acqtime = Timestamp<AcqtimeMarker>;
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct PubtimeMarker;
impl TimestampMarker for PubtimeMarker {
fn display_str_short() -> &'static str {
"PubT"
}
}
pub type Pubtime = Timestamp<PubtimeMarker>;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TimestampKind {
Acq,
Pub,
}
impl ops::Index<TimestampKind> for Stamp {
type Output = Duration;
fn index(&self, idx: TimestampKind) -> &Self::Output {
match idx {
TimestampKind::Acq => &self.acqtime,
TimestampKind::Pub => &self.pubtime,
}
}
}
pub trait WithAcqtime {
fn acqtime(&self) -> Acqtime;
}