Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd as_nanos function to Duration #50167
Conversation
fintelia
added some commits
Apr 22, 2018
rust-highfive
assigned
aidanhs
Apr 22, 2018
This comment has been minimized.
This comment has been minimized.
|
r? @aidanhs (rust_highfive has picked a reviewer for you, use r? to override) |
rust-highfive
added
the
S-waiting-on-review
label
Apr 22, 2018
This comment was marked as resolved.
This comment was marked as resolved.
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
kennytm
added
the
T-libs
label
Apr 24, 2018
kennytm
reviewed
Apr 24, 2018
| /// let duration = Duration::new(5, 730023852); | ||
| /// assert_eq!(duration.as_nanos(), 5730023852); | ||
| /// ``` | ||
| #[unstable(feature = "duration_nanos", issue = "50167")] |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
fintelia
referenced this pull request
Apr 24, 2018
Closed
Tracking Issue: Duration::{as_nanos, as_micros, as_millis} #50202
This comment has been minimized.
This comment has been minimized.
|
Reassigning this to someone from the libs team. |
rust-highfive
assigned
sfackler
and unassigned
aidanhs
Apr 30, 2018
This comment has been minimized.
This comment has been minimized.
|
We should add similar accessors for milliseconds and microseconds at the same time for consistency with the subsec methods. |
This comment has been minimized.
This comment has been minimized.
|
@sfackler I can make that change. Any thoughts on what the feature should be called then? "duration_as_nanos" isn't really a great name if it also adds as_millis() and as_micros(). Perhaps "duration_as_u128"? |
This comment has been minimized.
This comment has been minimized.
|
Sure, seems reasonable. |
shepmaster
added
S-waiting-on-author
and removed
S-waiting-on-review
labels
May 6, 2018
This comment has been minimized.
This comment has been minimized.
|
Ping from triage @fintelia! It's been a while since we heard from you, will you have time to work on this again soon? |
This comment has been minimized.
This comment has been minimized.
|
Sorry about that. I'm probably going to be busy for about a week longer, so if someone else wants to take over making those changes, feel free |
This comment has been minimized.
This comment has been minimized.
|
@fintelia don't worry, we just want to make sure you still remember about the PR |
kennytm
added
S-waiting-on-review
and removed
S-waiting-on-author
labels
May 20, 2018
lolgesten
referenced this pull request
May 21, 2018
Closed
Add as_millis function to std::time::Duration #1545
clarfon
reviewed
May 27, 2018
| #[unstable(feature = "duration_as_u128", issue = "50202")] | ||
| #[inline] | ||
| pub fn as_millis(&self) -> u128 { | ||
| self.secs as u128 * MILLIS_PER_SEC as u128 + self.nanos as u128 / NANOS_PER_MILLI as u128 |
This comment has been minimized.
This comment has been minimized.
clarfon
May 27, 2018
Contributor
Nit: self.nanos as u128 / NANOS_PER_MILLI as u128 should be replaced with (self.nanos / NANOS_PER_MILLI) as u128. The former requires doing 128-bit arithmetic on a 32-bit number, which is redundant.
clarfon
reviewed
May 27, 2018
| #[unstable(feature = "duration_as_u128", issue = "50202")] | ||
| #[inline] | ||
| pub fn as_micros(&self) -> u128 { | ||
| self.secs as u128 * MICROS_PER_SEC as u128 + self.nanos as u128 / NANOS_PER_MICRO as u128 |
This comment has been minimized.
This comment has been minimized.
clarfon
reviewed
May 27, 2018
| #[unstable(feature = "duration_as_u128", issue = "50202")] | ||
| #[inline] | ||
| pub fn as_nanos(&self) -> u128 { | ||
| self.secs as u128 * NANOS_PER_SEC as u128 + self.nanos as u128 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Ping from triage, @sfackler ! |
This comment has been minimized.
This comment has been minimized.
|
Oops - seems good to me! @bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
bors
added
S-waiting-on-bors
and removed
S-waiting-on-review
labels
Jun 2, 2018
Mark-Simulacrum
added a commit
to Mark-Simulacrum/rust
that referenced
this pull request
Jun 2, 2018
bors
added a commit
that referenced
this pull request
Jun 2, 2018
bors
merged commit fc89566
into
rust-lang:master
Jun 3, 2018
1 check passed
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
|
fintelia commentedApr 22, 2018
Duration has historically lacked a way to get the actual number of nanoseconds it contained as a normal Rust type because u64 was of insufficient range, and f64 of insufficient precision. The u128 type solves both issues, so I propose adding an
as_nanosfunction to expose the capability.