use std::{
sync::atomic::Ordering,
time::{Duration, Instant},
};
use crate::AtomicInstant;
impl AtomicInstant {
pub fn fetch_add(&self, val: Duration, order: Ordering) -> Instant {
self.instant_from_offset_nanos(self.offset_nanos.fetch_add(val.into_nanos(), order))
}
pub fn fetch_sub(&self, val: Duration, order: Ordering) -> Instant {
self.instant_from_offset_nanos(self.offset_nanos.fetch_sub(val.into_nanos(), order))
}
}
trait IntoNanos {
fn into_nanos(self) -> usize;
}
impl IntoNanos for Duration {
fn into_nanos(self) -> usize {
self.as_nanos().try_into().unwrap()
}
}