Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/libcore/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,23 @@ impl Duration {
#[inline]
pub fn subsec_nanos(&self) -> u32 { self.nanos }

/// Returns the total number of nanoseconds contained by this `Duration`.
///
/// # Examples
///
/// ```
/// # #![feature(duration_nanos)]
/// use std::time::Duration;
///
/// let duration = Duration::new(5, 730023852);
/// assert_eq!(duration.as_nanos(), 5730023852);
/// ```
#[unstable(feature = "duration_nanos", issue = "50167")]
Copy link
Member

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

#[inline]
pub fn as_nanos(&self) -> u128 {
self.secs as u128 * NANOS_PER_SEC as u128 + self.nanos as u128
Copy link
Contributor

Choose a reason for hiding this comment

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

See comment from as_nanos

}

/// Checked `Duration` addition. Computes `self + other`, returning [`None`]
/// if overflow occurred.
///
Expand Down