summaryrefslogtreecommitdiff
path: root/src/sys/time.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/sys/time.rs')
-rw-r--r--src/sys/time.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/sys/time.rs b/src/sys/time.rs
index 7546d1b3..c786500a 100644
--- a/src/sys/time.rs
+++ b/src/sys/time.rs
@@ -77,11 +77,7 @@ impl From<timespec> for TimeSpec {
impl From<Duration> for TimeSpec {
fn from(duration: Duration) -> Self {
- #[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
- TimeSpec(timespec {
- tv_sec: duration.as_secs() as time_t,
- tv_nsec: duration.subsec_nanos() as timespec_tv_nsec_t
- })
+ Self::from_duration(duration)
}
}
@@ -198,6 +194,18 @@ impl TimeSpec {
pub fn tv_nsec(&self) -> timespec_tv_nsec_t {
self.0.tv_nsec
}
+
+ pub const fn from_duration(duration: Duration) -> Self {
+ #[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
+ TimeSpec(timespec {
+ tv_sec: duration.as_secs() as time_t,
+ tv_nsec: duration.subsec_nanos() as timespec_tv_nsec_t
+ })
+ }
+
+ pub const fn from_timespec(timespec: timespec) -> Self {
+ Self(timespec)
+ }
}
impl ops::Neg for TimeSpec {