Struct std::time::Duration [] [src]

pub struct Duration {
    // some fields omitted
}
1.3.0

A duration type to represent a span of time, typically used for system timeouts.

Each duration is composed of a number of seconds and nanosecond precision. APIs binding a system timeout will typically round up the nanosecond precision if the underlying system does not support that level of precision.

Durations implement many common traits, including Add, Sub, and other ops traits. Currently a duration may only be inspected for its number of seconds and its nanosecond precision.

Examples

fn main() { use std::time::Duration; let five_seconds = Duration::new(5, 0); let five_seconds_and_five_nanos = five_seconds + Duration::new(0, 5); assert_eq!(five_seconds_and_five_nanos.as_secs(), 5); assert_eq!(five_seconds_and_five_nanos.subsec_nanos(), 5); let ten_millis = Duration::from_millis(10); }
use std::time::Duration;

let five_seconds = Duration::new(5, 0);
let five_seconds_and_five_nanos = five_seconds + Duration::new(0, 5);

assert_eq!(five_seconds_and_five_nanos.as_secs(), 5);
assert_eq!(five_seconds_and_five_nanos.subsec_nanos(), 5);

let ten_millis = Duration::from_millis(10);

Methods

impl Duration

fn new(secs: u64, nanos: u32) -> Duration

Creates a new Duration from the specified number of seconds and additional nanosecond precision.

If the nanoseconds is greater than 1 billion (the number of nanoseconds in a second), then it will carry over into the seconds provided.

fn from_secs(secs: u64) -> Duration

Creates a new Duration from the specified number of seconds.

fn from_millis(millis: u64) -> Duration

Creates a new Duration from the specified number of milliseconds.

fn as_secs(&self) -> u64

Returns the number of whole seconds represented by this duration.

The extra precision represented by this duration is ignored (e.g. extra nanoseconds are not represented in the returned value).

fn subsec_nanos(&self) -> u32

Returns the nanosecond precision represented by this duration.

This method does not return the length of the duration when represented by nanoseconds. The returned number always represents a fractional portion of a second (e.g. it is less than one billion).

Trait Implementations

impl Add for Duration

type Output = Duration

fn add(self, rhs: Duration) -> Duration

impl AddAssign for Duration1.9.0

fn add_assign(&mut self, rhs: Duration)

impl Sub for Duration

type Output = Duration

fn sub(self, rhs: Duration) -> Duration

impl SubAssign for Duration1.9.0

fn sub_assign(&mut self, rhs: Duration)

impl Mul<u32> for Duration

type Output = Duration

fn mul(self, rhs: u32) -> Duration

impl MulAssign<u32> for Duration1.9.0

fn mul_assign(&mut self, rhs: u32)

impl Div<u32> for Duration

type Output = Duration

fn div(self, rhs: u32) -> Duration

impl DivAssign<u32> for Duration1.9.0

fn div_assign(&mut self, rhs: u32)

Derived Implementations

impl Hash for Duration

fn hash<__H: Hasher>(&self, __arg_0: &mut __H)

fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher

impl Debug for Duration

fn fmt(&self, __arg_0: &mut Formatter) -> Result

impl Ord for Duration

fn cmp(&self, __arg_0: &Duration) -> Ordering

impl PartialOrd for Duration

fn partial_cmp(&self, __arg_0: &Duration) -> Option<Ordering>

fn lt(&self, __arg_0: &Duration) -> bool

fn le(&self, __arg_0: &Duration) -> bool

fn gt(&self, __arg_0: &Duration) -> bool

fn ge(&self, __arg_0: &Duration) -> bool

impl Eq for Duration

impl PartialEq for Duration

fn eq(&self, __arg_0: &Duration) -> bool

fn ne(&self, __arg_0: &Duration) -> bool

impl Copy for Duration

impl Clone for Duration

fn clone(&self) -> Duration

fn clone_from(&mut self, source: &Self)1.0.0