use crate::timestamp::Timestamp;
use crate::traits::RawTimestamp;
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct Epoch<Ts = u128>
where
Ts: RawTimestamp,
{
size: u128,
timestamp: Timestamp<Ts>,
}
impl<Ts> Epoch<Ts>
where
Ts: RawTimestamp,
{
pub const fn new(size: u128, timestamp: Ts) -> Self {
Self {
size,
timestamp: Timestamp(timestamp),
}
}
pub const fn size(&self) -> u128 {
self.size
}
pub const fn timestamp(&self) -> &Timestamp<Ts> {
&self.timestamp
}
pub fn set_size(&mut self, size: u128) {
self.size = size;
}
pub fn with_size(self, size: u128) -> Self {
Self { size, ..self }
}
pub fn with_timestamp<U: RawTimestamp>(self, timestamp: U) -> Epoch<U> {
Epoch {
timestamp: Timestamp(timestamp),
size: self.size,
}
}
}