From 7f7a2e939682ba0fabea62a528cec4fec7148c42 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Sun, 6 Jan 2019 13:44:55 +0100 Subject: [PATCH 1/3] Add duration constants --- src/libcore/time.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index b12ee0497d2c2..30e0873a4a2ea 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -23,6 +23,22 @@ const MILLIS_PER_SEC: u64 = 1_000; const MICROS_PER_SEC: u64 = 1_000_000; const MAX_NANOS_F64: f64 = ((u64::MAX as u128 + 1)*(NANOS_PER_SEC as u128)) as f64; +/// The duration of one second. +#[unstable(feature = "duration_constants", issue = "0")] +pub const SECOND: Duration = Duration::from_secs(1); + +/// The duration of one millisecond. +#[unstable(feature = "duration_constants", issue = "0")] +pub const MILLISECOND: Duration = Duration::from_millis(1); + +/// The duration of one microsecond. +#[unstable(feature = "duration_constants", issue = "0")] +pub const MICROSECOND: Duration = Duration::from_micros(1); + +/// The duration of one nanosecond. +#[unstable(feature = "duration_constants", issue = "0")] +pub const NANOSECOND: Duration = Duration::from_nanos(1); + /// A `Duration` type to represent a span of time, typically used for system /// timeouts. /// From 72ec5aa08055fade5122cc306cd9a08c64d4b635 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Sun, 6 Jan 2019 14:02:42 +0100 Subject: [PATCH 2/3] Re-export constants from core into std --- src/libstd/lib.rs | 1 + src/libstd/time.rs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 6ded43dfed1f4..13669c1c0e1f5 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -248,6 +248,7 @@ #![feature(const_cstr_unchecked)] #![feature(core_intrinsics)] #![feature(dropck_eyepatch)] +#![feature(duration_constants)] #![feature(exact_size_is_empty)] #![feature(external_doc)] #![feature(fixed_size_array)] diff --git a/src/libstd/time.rs b/src/libstd/time.rs index ffe604cd33bd8..d8cdef8b2ab30 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -21,6 +21,9 @@ use sys_common::FromInner; #[stable(feature = "time", since = "1.3.0")] pub use core::time::Duration; +#[unstable(feature = "duration_constants", issue = "0")] +pub use core::time::{SECOND, MILLISECOND, MICROSECOND, NANOSECOND}; + /// A measurement of a monotonically nondecreasing clock. /// Opaque and useful only with `Duration`. /// From 8c902b66339f54b40d3033c864675929b2c8a65b Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Mon, 7 Jan 2019 11:39:22 +0100 Subject: [PATCH 3/3] Specify the tracking issue --- src/libcore/time.rs | 8 ++++---- src/libstd/time.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index 30e0873a4a2ea..a751965dffab3 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -24,19 +24,19 @@ const MICROS_PER_SEC: u64 = 1_000_000; const MAX_NANOS_F64: f64 = ((u64::MAX as u128 + 1)*(NANOS_PER_SEC as u128)) as f64; /// The duration of one second. -#[unstable(feature = "duration_constants", issue = "0")] +#[unstable(feature = "duration_constants", issue = "57391")] pub const SECOND: Duration = Duration::from_secs(1); /// The duration of one millisecond. -#[unstable(feature = "duration_constants", issue = "0")] +#[unstable(feature = "duration_constants", issue = "57391")] pub const MILLISECOND: Duration = Duration::from_millis(1); /// The duration of one microsecond. -#[unstable(feature = "duration_constants", issue = "0")] +#[unstable(feature = "duration_constants", issue = "57391")] pub const MICROSECOND: Duration = Duration::from_micros(1); /// The duration of one nanosecond. -#[unstable(feature = "duration_constants", issue = "0")] +#[unstable(feature = "duration_constants", issue = "57391")] pub const NANOSECOND: Duration = Duration::from_nanos(1); /// A `Duration` type to represent a span of time, typically used for system diff --git a/src/libstd/time.rs b/src/libstd/time.rs index d8cdef8b2ab30..5d9c726995a34 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -21,7 +21,7 @@ use sys_common::FromInner; #[stable(feature = "time", since = "1.3.0")] pub use core::time::Duration; -#[unstable(feature = "duration_constants", issue = "0")] +#[unstable(feature = "duration_constants", issue = "57391")] pub use core::time::{SECOND, MILLISECOND, MICROSECOND, NANOSECOND}; /// A measurement of a monotonically nondecreasing clock.