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, 18 insertions, 0 deletions
diff --git a/src/sys/time.rs b/src/sys/time.rs
index c559cc47..b7ab3986 100644
--- a/src/sys/time.rs
+++ b/src/sys/time.rs
@@ -330,6 +330,15 @@ impl TimeValLike for TimeSpec {
}
impl TimeSpec {
+ /// Construct a new `TimeSpec` from its components
+ #[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
+ pub const fn new(seconds: time_t, nanoseconds: timespec_tv_nsec_t) -> Self {
+ Self(timespec {
+ tv_sec: seconds,
+ tv_nsec: nanoseconds,
+ })
+ }
+
fn nanos_mod_sec(&self) -> timespec_tv_nsec_t {
if self.tv_sec() < 0 && self.tv_nsec() > 0 {
self.tv_nsec() - NANOS_PER_SEC as timespec_tv_nsec_t
@@ -564,6 +573,15 @@ impl TimeValLike for TimeVal {
}
impl TimeVal {
+ /// Construct a new `TimeVal` from its components
+ #[cfg_attr(target_env = "musl", allow(deprecated))] // https://github.com/rust-lang/libc/issues/1848
+ pub const fn new(seconds: time_t, microseconds: suseconds_t) -> Self {
+ Self(timeval {
+ tv_sec: seconds,
+ tv_usec: microseconds,
+ })
+ }
+
fn micros_mod_sec(&self) -> suseconds_t {
if self.tv_sec() < 0 && self.tv_usec() > 0 {
self.tv_usec() - MICROS_PER_SEC as suseconds_t