-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add Duration::from_micros #44436
Conversation
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. |
This'll need a feature gate (right?). You'll need to:
|
|
src/libstd/time/duration.rs
Outdated
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 { |
There was a problem hiding this comment.
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.
I have commited some changes according to your feedbacks, please let me know if it needs anything else. |
src/libstd/time/duration.rs
Outdated
@@ -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 } | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You missed a }
here.
Thanks @kennytm, fixed! |
src/libstd/time/duration.rs
Outdated
#[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; |
There was a problem hiding this comment.
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`.
src/libstd/time/duration.rs
Outdated
/// assert_eq!(1, duration.as_secs()); | ||
/// assert_eq!(2000, duration.subsec_nanos()); | ||
/// ``` | ||
#[unstable(feature = "", issue = "44400")] |
There was a problem hiding this comment.
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 | ||
/// | ||
/// ``` |
There was a problem hiding this comment.
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.
Seems like a straightforward/reasonable addition! @rfcbot fcp merge |
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. |
Thanks for the review @sfackler, I have added a feature name as you suggested and used it in the test. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period is now complete. |
@bors: r+ |
📌 Commit b40a9f4 has been approved by |
Add Duration::from_micros This fixes #44400 that explains why it could be useful for embedded designs timing.
☀️ Test successful - status-appveyor, status-travis |
This fixes #44400 that explains why it could be useful for embedded designs timing.