Skip to content

Commit 1775299

Browse files
authored
Rollup merge of rust-lang#58595 - stjepang:make-duration-consts-associated, r=oli-obk
Turn duration consts into associated consts As suggested in rust-lang#57391 (comment), I'm moving `Duration` constants (`SECOND`, `MILLISECOND` and so on; currently behind unstable `duration_constants` feature) into the `impl Duration` block. cc @frewsxcv @SimonSapin
2 parents cb48a98 + c6d24cd commit 1775299

File tree

2 files changed

+52
-19
lines changed

2 files changed

+52
-19
lines changed

src/libcore/time.rs

+52-16
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,6 @@ const MILLIS_PER_SEC: u64 = 1_000;
2323
const MICROS_PER_SEC: u64 = 1_000_000;
2424
const MAX_NANOS_F64: f64 = ((u64::MAX as u128 + 1)*(NANOS_PER_SEC as u128)) as f64;
2525

26-
/// The duration of one second.
27-
#[unstable(feature = "duration_constants", issue = "57391")]
28-
pub const SECOND: Duration = Duration::from_secs(1);
29-
30-
/// The duration of one millisecond.
31-
#[unstable(feature = "duration_constants", issue = "57391")]
32-
pub const MILLISECOND: Duration = Duration::from_millis(1);
33-
34-
/// The duration of one microsecond.
35-
#[unstable(feature = "duration_constants", issue = "57391")]
36-
pub const MICROSECOND: Duration = Duration::from_micros(1);
37-
38-
/// The duration of one nanosecond.
39-
#[unstable(feature = "duration_constants", issue = "57391")]
40-
pub const NANOSECOND: Duration = Duration::from_nanos(1);
41-
4226
/// A `Duration` type to represent a span of time, typically used for system
4327
/// timeouts.
4428
///
@@ -75,6 +59,58 @@ pub struct Duration {
7559
}
7660

7761
impl Duration {
62+
/// The duration of one second.
63+
///
64+
/// # Examples
65+
///
66+
/// ```
67+
/// #![feature(duration_constants)]
68+
/// use std::time::Duration;
69+
///
70+
/// assert_eq!(Duration::SECOND, Duration::from_secs(1));
71+
/// ```
72+
#[unstable(feature = "duration_constants", issue = "57391")]
73+
pub const SECOND: Duration = Duration::from_secs(1);
74+
75+
/// The duration of one millisecond.
76+
///
77+
/// # Examples
78+
///
79+
/// ```
80+
/// #![feature(duration_constants)]
81+
/// use std::time::Duration;
82+
///
83+
/// assert_eq!(Duration::MILLISECOND, Duration::from_millis(1));
84+
/// ```
85+
#[unstable(feature = "duration_constants", issue = "57391")]
86+
pub const MILLISECOND: Duration = Duration::from_millis(1);
87+
88+
/// The duration of one microsecond.
89+
///
90+
/// # Examples
91+
///
92+
/// ```
93+
/// #![feature(duration_constants)]
94+
/// use std::time::Duration;
95+
///
96+
/// assert_eq!(Duration::MICROSECOND, Duration::from_micros(1));
97+
/// ```
98+
#[unstable(feature = "duration_constants", issue = "57391")]
99+
pub const MICROSECOND: Duration = Duration::from_micros(1);
100+
101+
/// The duration of one nanosecond.
102+
///
103+
/// # Examples
104+
///
105+
/// ```
106+
/// #![feature(duration_constants)]
107+
/// use std::time::Duration;
108+
///
109+
/// assert_eq!(Duration::NANOSECOND, Duration::from_nanos(1));
110+
/// ```
111+
#[unstable(feature = "duration_constants", issue = "57391")]
112+
pub const NANOSECOND: Duration = Duration::from_nanos(1);
113+
78114
/// Creates a new `Duration` from the specified number of whole seconds and
79115
/// additional nanoseconds.
80116
///

src/libstd/time.rs

-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ use sys_common::mutex::Mutex;
2323
#[stable(feature = "time", since = "1.3.0")]
2424
pub use core::time::Duration;
2525

26-
#[unstable(feature = "duration_constants", issue = "57391")]
27-
pub use core::time::{SECOND, MILLISECOND, MICROSECOND, NANOSECOND};
28-
2926
/// A measurement of a monotonically nondecreasing clock.
3027
/// Opaque and useful only with `Duration`.
3128
///

0 commit comments

Comments
 (0)