Newer
Older
use std::ops::Sub;
use std::time::{Duration, Instant};
#[derive(Copy, Clone, PartialEq, PartialOrd, Debug)]
pub struct Spot {
inner: Instant,
}
impl Spot {
pub fn now() -> Self {
Spot {
inner: Instant::now(),
}
}
pub fn as_secs(&self) -> u64 {
self.as_duration().as_secs()
}
pub fn as_duration(&self) -> Duration {
self.inner.elapsed()
}
pub fn elapsed(&self) -> Duration {
self.as_duration()
}
}
impl Sub<Spot> for Spot {
type Output = Duration;
fn sub(self, rhs: Spot) -> Self::Output {
self.inner - rhs.inner
}
}