From 8e219e7eb5ed554e0602476edfbbee5720e5c36e Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Wed, 20 Feb 2019 14:21:15 +0100 Subject: [PATCH 1/3] Turn duration consts into associated consts --- src/libcore/time.rs | 32 ++++++++++++++++---------------- src/libstd/time.rs | 3 --- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index a751965dffab3..62ed8d6f7906a 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -23,22 +23,6 @@ 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 = "57391")] -pub const SECOND: Duration = Duration::from_secs(1); - -/// The duration of one millisecond. -#[unstable(feature = "duration_constants", issue = "57391")] -pub const MILLISECOND: Duration = Duration::from_millis(1); - -/// The duration of one microsecond. -#[unstable(feature = "duration_constants", issue = "57391")] -pub const MICROSECOND: Duration = Duration::from_micros(1); - -/// The duration of one nanosecond. -#[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 /// timeouts. /// @@ -75,6 +59,22 @@ pub struct Duration { } impl Duration { + /// The duration of one second. + #[unstable(feature = "duration_constants", issue = "57391")] + pub const SECOND: Duration = Duration::from_secs(1); + + /// The duration of one millisecond. + #[unstable(feature = "duration_constants", issue = "57391")] + pub const MILLISECOND: Duration = Duration::from_millis(1); + + /// The duration of one microsecond. + #[unstable(feature = "duration_constants", issue = "57391")] + pub const MICROSECOND: Duration = Duration::from_micros(1); + + /// The duration of one nanosecond. + #[unstable(feature = "duration_constants", issue = "57391")] + pub const NANOSECOND: Duration = Duration::from_nanos(1); + /// Creates a new `Duration` from the specified number of whole seconds and /// additional nanoseconds. /// diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 507ea395c6c6c..72a5a070233e1 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -23,9 +23,6 @@ use sys_common::mutex::Mutex; #[stable(feature = "time", since = "1.3.0")] pub use core::time::Duration; -#[unstable(feature = "duration_constants", issue = "57391")] -pub use core::time::{SECOND, MILLISECOND, MICROSECOND, NANOSECOND}; - /// A measurement of a monotonically nondecreasing clock. /// Opaque and useful only with `Duration`. /// From f223c03372f198d4fc50960288fc033f9de5da10 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Wed, 20 Feb 2019 21:58:20 +0100 Subject: [PATCH 2/3] Add examples for duration constants --- src/libcore/time.rs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index 62ed8d6f7906a..a28f690775be6 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -60,18 +60,50 @@ pub struct Duration { impl Duration { /// The duration of one second. + /// + /// # Examples + /// + /// ``` + /// use std::time::Duration; + /// + /// assert_eq!(Duration::SECOND, Duration::from_secs(1)); + /// ``` #[unstable(feature = "duration_constants", issue = "57391")] pub const SECOND: Duration = Duration::from_secs(1); /// The duration of one millisecond. + /// + /// # Examples + /// + /// ``` + /// use std::time::Duration; + /// + /// assert_eq!(Duration::MILLISECOND, Duration::from_millis(1)); + /// ``` #[unstable(feature = "duration_constants", issue = "57391")] pub const MILLISECOND: Duration = Duration::from_millis(1); /// The duration of one microsecond. + /// + /// # Examples + /// + /// ``` + /// use std::time::Duration; + /// + /// assert_eq!(Duration::MICROSECOND, Duration::from_micros(1)); + /// ``` #[unstable(feature = "duration_constants", issue = "57391")] pub const MICROSECOND: Duration = Duration::from_micros(1); /// The duration of one nanosecond. + /// + /// # Examples + /// + /// ``` + /// use std::time::Duration; + /// + /// assert_eq!(Duration::NANOSECOND, Duration::from_nanos(1)); + /// ``` #[unstable(feature = "duration_constants", issue = "57391")] pub const NANOSECOND: Duration = Duration::from_nanos(1); From c6d24cd50435f008cc8bf1a00a656b36ca892b5d Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Thu, 21 Feb 2019 09:13:50 +0100 Subject: [PATCH 3/3] Enable feature duration_constants in examples --- src/libcore/time.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libcore/time.rs b/src/libcore/time.rs index a28f690775be6..ceeb9ace7e02d 100644 --- a/src/libcore/time.rs +++ b/src/libcore/time.rs @@ -64,6 +64,7 @@ impl Duration { /// # Examples /// /// ``` + /// #![feature(duration_constants)] /// use std::time::Duration; /// /// assert_eq!(Duration::SECOND, Duration::from_secs(1)); @@ -76,6 +77,7 @@ impl Duration { /// # Examples /// /// ``` + /// #![feature(duration_constants)] /// use std::time::Duration; /// /// assert_eq!(Duration::MILLISECOND, Duration::from_millis(1)); @@ -88,6 +90,7 @@ impl Duration { /// # Examples /// /// ``` + /// #![feature(duration_constants)] /// use std::time::Duration; /// /// assert_eq!(Duration::MICROSECOND, Duration::from_micros(1)); @@ -100,6 +103,7 @@ impl Duration { /// # Examples /// /// ``` + /// #![feature(duration_constants)] /// use std::time::Duration; /// /// assert_eq!(Duration::NANOSECOND, Duration::from_nanos(1));