diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-10-06 16:29:47 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-10-09 09:44:51 -0700 |
| commit | ab5935c88d259d511561ccb4177bb6924dab4a06 (patch) | |
| tree | f23ddc5fb8733a5eeb5f3fbac06b99159139687e /src/libstd/time | |
| parent | d9874bfb4079876dabc092c035d99b2d5b7f8a1c (diff) | |
| download | rust-ab5935c88d259d511561ccb4177bb6924dab4a06.tar.gz rust-ab5935c88d259d511561ccb4177bb6924dab4a06.zip | |
std: Convert statics to constants
This commit repurposes most statics as constants in the standard library itself, with the exception of TLS keys which precisely have their own memory location as an implementation detail. This commit also rewrites the bitflags syntax to use `const` instead of `static`. All invocations will need to replace the word `static` with `const` when declaring flags. Due to the modification of the `bitflags!` syntax, this is a: [breaking-change]
Diffstat (limited to 'src/libstd/time')
| -rw-r--r-- | src/libstd/time/duration.rs | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index 85aed47265f..751eb00bfae 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -20,23 +20,23 @@ use num::{CheckedAdd, CheckedMul}; use result::{Result, Ok, Err}; /// The number of nanoseconds in a microsecond. -static NANOS_PER_MICRO: i32 = 1000; +const NANOS_PER_MICRO: i32 = 1000; /// The number of nanoseconds in a millisecond. -static NANOS_PER_MILLI: i32 = 1000_000; +const NANOS_PER_MILLI: i32 = 1000_000; /// The number of nanoseconds in seconds. -static NANOS_PER_SEC: i32 = 1_000_000_000; +const NANOS_PER_SEC: i32 = 1_000_000_000; /// The number of microseconds per second. -static MICROS_PER_SEC: i64 = 1000_000; +const MICROS_PER_SEC: i64 = 1000_000; /// The number of milliseconds per second. -static MILLIS_PER_SEC: i64 = 1000; +const MILLIS_PER_SEC: i64 = 1000; /// The number of seconds in a minute. -static SECS_PER_MINUTE: i64 = 60; +const SECS_PER_MINUTE: i64 = 60; /// The number of seconds in an hour. -static SECS_PER_HOUR: i64 = 3600; +const SECS_PER_HOUR: i64 = 3600; /// The number of (non-leap) seconds in days. -static SECS_PER_DAY: i64 = 86400; +const SECS_PER_DAY: i64 = 86400; /// The number of (non-leap) seconds in a week. -static SECS_PER_WEEK: i64 = 604800; +const SECS_PER_WEEK: i64 = 604800; macro_rules! try_opt( ($e:expr) => (match $e { Some(v) => v, None => return None }) @@ -52,13 +52,13 @@ pub struct Duration { } /// The minimum possible `Duration`: `i64::MIN` milliseconds. -pub static MIN: Duration = Duration { +pub const MIN: Duration = Duration { secs: i64::MIN / MILLIS_PER_SEC - 1, nanos: NANOS_PER_SEC + (i64::MIN % MILLIS_PER_SEC) as i32 * NANOS_PER_MILLI }; /// The maximum possible `Duration`: `i64::MAX` milliseconds. -pub static MAX: Duration = Duration { +pub const MAX: Duration = Duration { secs: i64::MAX / MILLIS_PER_SEC, nanos: (i64::MAX % MILLIS_PER_SEC) as i32 * NANOS_PER_MILLI }; @@ -456,7 +456,7 @@ mod tests { assert_eq!(MIN.num_microseconds(), None); // overflow checks - static MICROS_PER_DAY: i64 = 86400_000_000; + const MICROS_PER_DAY: i64 = 86400_000_000; assert_eq!(Duration::days(i64::MAX / MICROS_PER_DAY).num_microseconds(), Some(i64::MAX / MICROS_PER_DAY * MICROS_PER_DAY)); assert_eq!(Duration::days(i64::MIN / MICROS_PER_DAY).num_microseconds(), @@ -477,7 +477,7 @@ mod tests { assert_eq!(MIN.num_nanoseconds(), None); // overflow checks - static NANOS_PER_DAY: i64 = 86400_000_000_000; + const NANOS_PER_DAY: i64 = 86400_000_000_000; assert_eq!(Duration::days(i64::MAX / NANOS_PER_DAY).num_nanoseconds(), Some(i64::MAX / NANOS_PER_DAY * NANOS_PER_DAY)); assert_eq!(Duration::days(i64::MIN / NANOS_PER_DAY).num_nanoseconds(), |
