blob: 966c239699cecc1ae5065fc7ddef94fba1373eb0 [file] [log] [blame] [edit]
use crate::time::Duration;
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
pub struct Instant(Duration);
impl Instant {
pub fn now() -> Instant {
let micros = unsafe { vex_sdk::vexSystemHighResTimeGet() };
Self(Duration::from_micros(micros))
}
pub fn checked_sub_instant(&self, other: &Instant) -> Option<Duration> {
self.0.checked_sub(other.0)
}
pub fn checked_add_duration(&self, other: &Duration) -> Option<Instant> {
Some(Instant(self.0.checked_add(*other)?))
}
pub fn checked_sub_duration(&self, other: &Duration) -> Option<Instant> {
Some(Instant(self.0.checked_sub(*other)?))
}
}