use crate::{Error, Tick};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Window {
earliest: Tick,
latest: Tick,
}
impl Window {
pub const fn new(earliest: Tick, latest: Tick) -> Result<Self, Error> {
if earliest > latest {
return Err(Error::InvalidWindow { earliest, latest });
}
Ok(Self { earliest, latest })
}
#[must_use]
pub const fn at(start: Tick) -> Self {
Self {
earliest: start,
latest: start,
}
}
#[must_use]
pub const fn earliest(&self) -> Tick {
self.earliest
}
#[must_use]
pub const fn latest(&self) -> Tick {
self.latest
}
#[must_use]
pub const fn contains(&self, t: Tick) -> bool {
self.earliest <= t && t <= self.latest
}
}