Rollup merge of #58595 - stjepang:make-duration-consts-associated, r=oli-obk

Turn duration consts into associated consts

As suggested in https://github.com/rust-lang/rust/issues/57391#issuecomment-459658236, I'm moving `Duration` constants (`SECOND`, `MILLISECOND` and so on; currently behind unstable `duration_constants` feature) into the `impl Duration` block.

cc @frewsxcv @SimonSapin
This commit is contained in:
Mazdak Farrokhzad 2019-02-23 09:25:29 +01:00 committed by GitHub
commit 73e661a0a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 52 additions and 19 deletions

View File

@ -23,22 +23,6 @@
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,58 @@ pub struct Duration {
}
impl Duration {
/// The duration of one second.
///
/// # Examples
///
/// ```
/// #![feature(duration_constants)]
/// 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
///
/// ```
/// #![feature(duration_constants)]
/// 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
///
/// ```
/// #![feature(duration_constants)]
/// 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
///
/// ```
/// #![feature(duration_constants)]
/// 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);
/// Creates a new `Duration` from the specified number of whole seconds and
/// additional nanoseconds.
///

View File

@ -23,9 +23,6 @@
#[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`.
///