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::from_micros #44436

Merged
merged 6 commits into from
Sep 24, 2017
Merged

Add Duration::from_micros #44436

merged 6 commits into from
Sep 24, 2017

Conversation

gagath
Copy link
Contributor

@gagath gagath commented Sep 8, 2017

This fixes #44400 that explains why it could be useful for embedded designs timing.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sfackler (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@mattico
Copy link
Contributor

mattico commented Sep 8, 2017

This'll need a feature gate (right?).

You'll need to:

@sfackler
Copy link
Member

sfackler commented Sep 8, 2017

src/libsyntax/feature_gate.rs is only used for language features, not library features. I don't think the unstable book needs to be modified anymore either.

pub fn from_micros(micros: u64) -> Duration {
let secs = micros / MICROS_PER_SEC;
let nanos = ((micros % MICROS_PER_SEC) as u32) * NANOS_PER_MICRO;
Duration {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be inlined for consistency.

@gagath
Copy link
Contributor Author

gagath commented Sep 9, 2017

I have commited some changes according to your feedbacks, please let me know if it needs anything else.

@@ -114,6 +116,25 @@ impl Duration {
let secs = millis / MILLIS_PER_SEC;
let nanos = ((millis % MILLIS_PER_SEC) as u32) * NANOS_PER_MILLI;
Duration { secs: secs, nanos: nanos }

Copy link
Member

Choose a reason for hiding this comment

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

You missed a } here.

@gagath
Copy link
Contributor Author

gagath commented Sep 9, 2017

Thanks @kennytm, fixed!

#[inline]
pub fn from_micros(micros: u64) -> Duration {
let secs = micros / MICROS_PER_SEC;
let nanos = ((micros % MICROS_PER_SEC) as u32) * NANOS_PER_MICRO;
Copy link
Member

Choose a reason for hiding this comment

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

Typo. Also, the issue must be a number.

[00:02:49] error[E0425]: cannot find value `NANOS_PER_MICRO` in this scope
[00:02:49]    --> /checkout/src/libstd/time/duration.rs:137:58
[00:02:49]     |
[00:02:49] 137 |         let nanos = ((micros % MICROS_PER_SEC) as u32) * NANOS_PER_MICRO;
[00:02:49]     |                                                          ^^^^^^^^^^^^^^^ did you mean `NANOS_PER_MICROS`?
[00:02:49] 
[00:02:49] error[E0545]: incorrect 'issue'
[00:02:49]    --> /checkout/src/libstd/time/duration.rs:133:5
[00:02:49]     |
[00:02:49] 133 |     #[unstable(feature = "", issue = "")]
[00:02:49]     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[00:02:49] 
[00:02:51] error: aborting due to 2 previous errors
[00:02:51] 
[00:02:51] error: Could not compile `std`.

@carols10cents carols10cents added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 11, 2017
/// assert_eq!(1, duration.as_secs());
/// assert_eq!(2000, duration.subsec_nanos());
/// ```
#[unstable(feature = "", issue = "44400")]
Copy link
Member

Choose a reason for hiding this comment

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

The feature can be called whatever you want duration_from_micros is probably fine.

///
/// # Examples
///
/// ```
Copy link
Member

Choose a reason for hiding this comment

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

This test will need to enable that feature to build properly.

@sfackler sfackler added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Sep 11, 2017
@sfackler
Copy link
Member

Seems like a straightforward/reasonable addition!

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Sep 11, 2017

Team member @sfackler has proposed to merge this. The next step is review by the rest of the tagged teams:

No concerns currently listed.

Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Sep 11, 2017
@gagath
Copy link
Contributor Author

gagath commented Sep 13, 2017

Thanks for the review @sfackler, I have added a feature name as you suggested and used it in the test.

@rfcbot rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Sep 13, 2017
@rfcbot
Copy link

rfcbot commented Sep 13, 2017

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Sep 13, 2017
@arielb1 arielb1 added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 19, 2017
@rfcbot
Copy link

rfcbot commented Sep 23, 2017

The final comment period is now complete.

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Sep 23, 2017

📌 Commit b40a9f4 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Sep 23, 2017

⌛ Testing commit b40a9f4 with merge 24831c7...

bors added a commit that referenced this pull request Sep 23, 2017
Add Duration::from_micros

This fixes #44400 that explains why it could be useful for embedded designs timing.
@bors
Copy link
Contributor

bors commented Sep 24, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 24831c7 to master...

@bors bors merged commit b40a9f4 into rust-lang:master Sep 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). 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.

Consider adding a from_micros for std::time::Duration