New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add duration constants #57375

Merged
merged 3 commits into from Jan 7, 2019

Conversation

Projects
None yet
8 participants
@stjepang
Copy link
Contributor

stjepang commented Jan 6, 2019

Add constants SECOND, MILLISECOND, MICROSECOND, and NANOSECOND to core::time.

This will make working with durations more ergonomic. Compare:

// Convenient, but deprecated function.
thread::sleep_ms(2000);

// The current canonical way to sleep for two seconds.
thread::sleep(Duration::from_secs(2));

// Sleeping using one of the new constants.
thread::sleep(2 * SECOND);
@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Jan 6, 2019

r? @joshtriplett

(rust_highfive has picked a reviewer for you, use r? to override)

@stjepang

This comment has been minimized.

Copy link
Contributor

stjepang commented Jan 6, 2019

Previous attempts to do something similar, but got stuck on bikeshedding: #52556 #51610

Since we already have std::time::UNIX_EPOCH, I hope adding a few more useful constants won't be too controversial.

@stjepang stjepang force-pushed the stjepang:duration-constants branch from 4265db6 to 72ec5aa Jan 6, 2019

@kennytm kennytm added the T-libs label Jan 6, 2019

@xfix

xfix approved these changes Jan 6, 2019

@joshtriplett

This comment has been minimized.

Copy link
Member

joshtriplett commented Jan 6, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 6, 2019

📌 Commit 72ec5aa has been approved by joshtriplett

@retep998

This comment has been minimized.

Copy link
Member

retep998 commented Jan 6, 2019

Shouldn't we create a tracking issue for this first?

@frewsxcv

This comment has been minimized.

Copy link
Member

frewsxcv commented Jan 6, 2019

@@ -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")]

This comment has been minimized.

@xfix

xfix Jan 6, 2019

Contributor

The issue number should be updated for the tracking issue in all places where the issue is mentioned.

This comment has been minimized.

@joshtriplett

joshtriplett Jan 6, 2019

Member

Ah, good call. @stjepang, can you please update those to reference the tracking issue?

This comment has been minimized.

@stjepang

stjepang Jan 7, 2019

Contributor

Done.

@joshtriplett

This comment has been minimized.

Copy link
Member

joshtriplett commented Jan 7, 2019

@bors r-

@joshtriplett

This comment has been minimized.

Copy link
Member

joshtriplett commented Jan 7, 2019

Thanks!

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jan 7, 2019

📌 Commit 8c902b6 has been approved by joshtriplett

@xfix

xfix approved these changes Jan 7, 2019

pietroalbini added a commit to pietroalbini/rust that referenced this pull request Jan 7, 2019

Rollup merge of rust-lang#57375 - stjepang:duration-constants, r=josh…
…triplett

Add duration constants

Add constants `SECOND`, `MILLISECOND`, `MICROSECOND`, and `NANOSECOND` to `core::time`.

This will make working with durations more ergonomic. Compare:

```rust
// Convenient, but deprecated function.
thread::sleep_ms(2000);

// The current canonical way to sleep for two seconds.
thread::sleep(Duration::from_secs(2));

// Sleeping using one of the new constants.
thread::sleep(2 * SECOND);
```

bors added a commit that referenced this pull request Jan 7, 2019

Auto merge of #57405 - pietroalbini:rollup, r=pietroalbini
Rollup of 6 pull requests

Successful merges:

 - #57290 (remove outdated comment)
 - #57308 (Make CompileController thread-safe)
 - #57358 (use utf-8 throughout htmldocck)
 - #57369 (Provide the option to use libc++ even on all platforms)
 - #57375 (Add duration constants)
 - #57403 (Make extern ref HTTPS)

Failed merges:

 - #57370 (Support passing cflags/cxxflags/ldflags to LLVM build)

r? @ghost

@bors bors merged commit 8c902b6 into rust-lang:master Jan 7, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment