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 as_nanos function to Duration #50167

Merged
merged 7 commits into from Jun 3, 2018

Conversation

Projects
None yet
9 participants
@fintelia
Copy link
Contributor

fintelia commented Apr 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_nanos function to expose the capability.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Apr 22, 2018

r? @aidanhs

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

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Apr 22, 2018

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[01:13:19] ....................................................................................................
[01:13:34] ....................................................................................................
[01:13:48] ....................................................................................................
[01:14:08] ....................................................................................................
[01:14:23] ....................i................................................F.................
[01:14:23] 
[01:14:23] 
[01:14:23] ---- time.rs - time::Duration::as_nanos (line 270) stdout ----
[01:14:23]  error[E0658]: use of unstable library feature 'duration_nanos' (see issue #50167)
[01:14:23]  --> time.rs:274:21
[01:14:23]   |
[01:14:23] 7 | assert_eq!(duration.as_nanos(), 5730023852);
[01:14:23]   |
[01:14:23]   |
[01:14:23]   = help: add #![feature(duration_nanos)] to the crate attributes to enable
[01:14:23] 
[01:14:23] thread 'time.rs - time::Duration::as_nanos (line 270)' panicked at 'couldn't compile the test', librustdoc/test.rs:321:13
[01:14:23] 
[01:14:23] 
[01:14:23] failures:
[01:14:23]     time.rs - time::Duration::as_nanos (line 270)
[01:14:23]     time.rs - time::Duration::as_nanos (line 270)
[01:14:23] 
[01:14:23] test result: FAILED. 1984 passed; 1 failed; 2 ignored; 0 measured; 0 filtered out
[01:14:23] 
[01:14:23] error: test failed, to rerun pass '--doc'
[01:14:23] 
[01:14:23] 
[01:14:23] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "test" "--target" "x86_64-unknown-linux-gnu" "--release" "--locked" "--color" "always" "--features" "panic-unwind jemalloc backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "-p" "core" "--" "--quiet"
[01:14:23] 
[01:14:23] 
[01:14:23] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:14:23] Build completed unsuccessfully in 0:34:30
[01:14:23] Build completed unsuccessfully in 0:34:30
[01:14:23] Makefile:58: recipe for target 'check' failed
[01:14:23] make: *** [check] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:2b36015a
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)

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 @TimNN. (Feature Requests)

@kennytm kennytm added the T-libs label 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.

@kennytm

kennytm Apr 24, 2018

Member

The tracking issue number should be a new issue, not this PR.

This comment has been minimized.

@fintelia

fintelia Apr 24, 2018

Author Contributor

Done.

@pietroalbini

This comment has been minimized.

Copy link
Member

pietroalbini commented Apr 30, 2018

Reassigning this to someone from the libs team.
r? @sfackler

@rust-highfive rust-highfive assigned sfackler and unassigned aidanhs Apr 30, 2018

@sfackler

This comment has been minimized.

Copy link
Member

sfackler commented May 1, 2018

We should add similar accessors for milliseconds and microseconds at the same time for consistency with the subsec methods.

cc @rust-lang/libs

@fintelia

This comment has been minimized.

Copy link
Contributor Author

fintelia commented May 1, 2018

@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"?

@sfackler

This comment has been minimized.

Copy link
Member

sfackler commented May 2, 2018

Sure, seems reasonable.

@pietroalbini

This comment has been minimized.

Copy link
Member

pietroalbini commented May 14, 2018

Ping from triage @fintelia! It's been a while since we heard from you, will you have time to work on this again soon?

@fintelia

This comment has been minimized.

Copy link
Contributor Author

fintelia commented May 14, 2018

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

@pietroalbini

This comment has been minimized.

Copy link
Member

pietroalbini commented May 14, 2018

@fintelia don't worry, we just want to make sure you still remember about the PR ;)
Someone from triage will ping you next week.

#[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.

@clarfon

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.

#[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.

@clarfon

clarfon May 27, 2018

Contributor

See comment from as_nanos

#[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.

@clarfon

clarfon May 27, 2018

Contributor

See comment from as_nanos

@shepmaster

This comment has been minimized.

Copy link
Member

shepmaster commented Jun 2, 2018

Ping from triage, @sfackler !

@sfackler

This comment has been minimized.

Copy link
Member

sfackler commented Jun 2, 2018

Oops - seems good to me!

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jun 2, 2018

📌 Commit fc89566 has been approved by sfackler

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Jun 2, 2018

Rollup merge of rust-lang#50167 - fintelia:duration-nanos, r=sfackler
 Add as_nanos function to Duration

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_nanos` function to expose the capability.

bors added a commit that referenced this pull request Jun 2, 2018

Auto merge of #51310 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 6 pull requests

Successful merges:

 - #50167 ( Add as_nanos function to Duration)
 - #50919 (Provide more context for what the {f32,f64}::EPSILON values represent.)
 - #51124 (Reword {ptr,mem}::replace docs.)
 - #51147 (Stabilize SliceIndex trait.)
 - #51291 (Fix typos of ‘ambiguous’)
 - #51302 (Permit building rustdoc without compiler artifacts)

Failed merges:

@bors bors merged commit fc89566 into rust-lang:master Jun 3, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jun 3, 2018

⌛️ Testing commit fc89566 with merge 3515dab...

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Jun 3, 2018

💥 Test timed out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.