use crate::SignedDuration;
use crate::unit::*;
mod sealed {
pub trait Sealed {}
impl Sealed for i64 {}
impl Sealed for f64 {}
}
#[diagnostic::on_unimplemented(note = "this extension trait is intended to be used with numeric \
literals, such as `5.seconds()`")]
pub trait NumericalDuration: sealed::Sealed {
fn nanoseconds(self) -> SignedDuration;
fn microseconds(self) -> SignedDuration;
fn milliseconds(self) -> SignedDuration;
fn seconds(self) -> SignedDuration;
fn minutes(self) -> SignedDuration;
fn hours(self) -> SignedDuration;
fn days(self) -> SignedDuration;
fn weeks(self) -> SignedDuration;
}
impl NumericalDuration for i64 {
#[inline]
fn nanoseconds(self) -> SignedDuration {
SignedDuration::nanoseconds(self)
}
#[inline]
fn microseconds(self) -> SignedDuration {
SignedDuration::microseconds(self)
}
#[inline]
fn milliseconds(self) -> SignedDuration {
SignedDuration::milliseconds(self)
}
#[inline]
fn seconds(self) -> SignedDuration {
SignedDuration::seconds(self)
}
#[inline]
#[track_caller]
fn minutes(self) -> SignedDuration {
SignedDuration::minutes(self)
}
#[inline]
#[track_caller]
fn hours(self) -> SignedDuration {
SignedDuration::hours(self)
}
#[inline]
#[track_caller]
fn days(self) -> SignedDuration {
SignedDuration::days(self)
}
#[inline]
#[track_caller]
fn weeks(self) -> SignedDuration {
SignedDuration::weeks(self)
}
}
impl NumericalDuration for f64 {
#[inline]
fn nanoseconds(self) -> SignedDuration {
SignedDuration::nanoseconds(self as i64)
}
#[inline]
fn microseconds(self) -> SignedDuration {
SignedDuration::nanoseconds((self * Nanosecond::per_t::<Self>(Microsecond)) as i64)
}
#[inline]
fn milliseconds(self) -> SignedDuration {
SignedDuration::nanoseconds((self * Nanosecond::per_t::<Self>(Millisecond)) as i64)
}
#[inline]
fn seconds(self) -> SignedDuration {
SignedDuration::nanoseconds((self * Nanosecond::per_t::<Self>(Second)) as i64)
}
#[inline]
#[track_caller]
fn minutes(self) -> SignedDuration {
SignedDuration::nanoseconds((self * Nanosecond::per_t::<Self>(Minute)) as i64)
}
#[inline]
#[track_caller]
fn hours(self) -> SignedDuration {
SignedDuration::nanoseconds((self * Nanosecond::per_t::<Self>(Hour)) as i64)
}
#[inline]
#[track_caller]
fn days(self) -> SignedDuration {
SignedDuration::nanoseconds((self * Nanosecond::per_t::<Self>(Day)) as i64)
}
#[inline]
#[track_caller]
fn weeks(self) -> SignedDuration {
SignedDuration::nanoseconds((self * Nanosecond::per_t::<Self>(Week)) as i64)
}
}