Add as_nanos function to duration
This commit is contained in:
parent
8887396513
commit
43baa2c041
1 changed files with 16 additions and 0 deletions
|
|
@ -263,6 +263,22 @@ impl Duration {
|
|||
#[inline]
|
||||
pub fn subsec_nanos(&self) -> u32 { self.nanos }
|
||||
|
||||
/// Returns the total number of nanoseconds contained by this `Duration`.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use std::time::Duration;
|
||||
///
|
||||
/// let duration = Duration::new(5, 730023852);
|
||||
/// assert_eq!(duration.as_nanos(), 5730023852);
|
||||
/// ```
|
||||
#[unstable(feature = "duration_nanos", issue = "0")]
|
||||
#[inline]
|
||||
pub fn as_nanos(&self) -> u128 {
|
||||
self.secs as u128 * 1000_000_000 + self.nanos as u128
|
||||
}
|
||||
|
||||
/// Checked `Duration` addition. Computes `self + other`, returning [`None`]
|
||||
/// if overflow occurred.
|
||||
///
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue