fuchsia_fuzzctl/
duration.rspub use self::platform::{deadline_after, MonotonicDuration};
#[cfg(not(target_os = "fuchsia"))]
mod platform {
use std::time::{Duration as OsDuration, Instant as OsTime};
#[derive(Debug)]
pub struct MonotonicDuration {
base: OsDuration,
}
impl MonotonicDuration {
pub const fn from_nanos(nanos: i64) -> Self {
Self { base: OsDuration::from_nanos(nanos as u64) }
}
pub const fn from_micros(micros: i64) -> Self {
Self { base: OsDuration::from_micros(micros as u64) }
}
pub const fn from_millis(millis: i64) -> Self {
Self { base: OsDuration::from_millis(millis as u64) }
}
pub const fn from_seconds(seconds: i64) -> Self {
Self { base: OsDuration::from_secs(seconds as u64) }
}
pub const fn into_nanos(self) -> i64 {
self.base.as_nanos() as i64
}
pub const fn into_seconds(self) -> i64 {
self.base.as_secs() as i64
}
}
pub fn deadline_after(timeout: Option<i64>) -> Option<fuchsia_async::MonotonicInstant> {
timeout.and_then(|nanos| OsTime::now().checked_add(OsDuration::from_nanos(nanos as u64)))
}
}
#[cfg(target_os = "fuchsia")]
mod platform {
use fuchsia_async::DurationExt;
pub use fuchsia_async::MonotonicDuration;
pub fn deadline_after(timeout: Option<i64>) -> Option<fuchsia_async::MonotonicInstant> {
timeout.map(|nanos| MonotonicDuration::from_nanos(nanos).after_now())
}
}