Skip to content
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
Merged

Add duration constants #57375

merged 3 commits into from Jan 7, 2019

Conversation

ghost
Copy link

@ghost ghost 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
Copy link
Collaborator

r? @joshtriplett

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 6, 2019
@ghost ghost mentioned this pull request Jan 6, 2019
@ghost
Copy link
Author

ghost 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.

@kennytm kennytm added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jan 6, 2019
@joshtriplett
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jan 6, 2019

📌 Commit 72ec5aa has been approved by joshtriplett

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 6, 2019
@retep998
Copy link
Member

retep998 commented Jan 6, 2019

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

@frewsxcv
Copy link
Member

frewsxcv commented Jan 6, 2019

#57391

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

@KamilaBorowska KamilaBorowska Jan 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@joshtriplett
Copy link
Member

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 7, 2019
@joshtriplett
Copy link
Member

Thanks!

@bors r+

@bors
Copy link
Contributor

bors commented Jan 7, 2019

📌 Commit 8c902b6 has been approved by joshtriplett

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 7, 2019
pietroalbini added a commit to pietroalbini/rust that referenced this pull request Jan 7, 2019
…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
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants