Struct sirpent::utils::Milliseconds [] [src]

pub struct Milliseconds { /* fields omitted */ }

Represents a duration in milliseconds.

Methods

impl Milliseconds
[src]

Methods from Deref<Target=Duration>

Returns the number of whole seconds represented by this Duration.

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

Examples

use std::time::Duration;

let five_seconds = Duration::new(5, 0);
assert_eq!(five_seconds.as_secs(), 5);

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 (i.e. it is less than one billion).

Examples

use std::time::Duration;

let duration = Duration::from_millis(5010);
assert_eq!(duration.subsec_nanos(), 10000000);

Checked Duration addition. Computes self + other, returning None if overflow occurred.

Examples

Basic usage:

use std::time::Duration;

assert_eq!(Duration::new(0, 0).checked_add(Duration::new(0, 1)), Some(Duration::new(0, 1)));
assert_eq!(Duration::new(1, 0).checked_add(Duration::new(std::u64::MAX, 0)), None);

Checked Duration subtraction. Computes self - other, returning None if the result would be negative or if underflow occurred.

Examples

Basic usage:

use std::time::Duration;

assert_eq!(Duration::new(0, 1).checked_sub(Duration::new(0, 0)), Some(Duration::new(0, 1)));
assert_eq!(Duration::new(0, 0).checked_sub(Duration::new(0, 1)), None);

Checked Duration multiplication. Computes self * other, returning None if overflow occurred.

Examples

Basic usage:

use std::time::Duration;

assert_eq!(Duration::new(0, 500_000_001).checked_mul(2), Some(Duration::new(1, 2)));
assert_eq!(Duration::new(std::u64::MAX - 1, 0).checked_mul(2), None);

Checked Duration division. Computes self / other, returning None if other == 0.

Examples

Basic usage:

use std::time::Duration;

assert_eq!(Duration::new(2, 0).checked_div(2), Some(Duration::new(1, 0)));
assert_eq!(Duration::new(1, 0).checked_div(2), Some(Duration::new(0, 500_000_000)));
assert_eq!(Duration::new(2, 0).checked_div(0), None);

Trait Implementations

impl PartialEq for Milliseconds
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Clone for Milliseconds
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Copy for Milliseconds
[src]

impl Debug for Milliseconds
[src]

Formats the value using the given formatter.

impl Deref for Milliseconds
[src]

The resulting type after dereferencing

The method called to dereference a value

impl Into<Duration> for Milliseconds
[src]

Performs the conversion.

impl Serialize for Milliseconds
[src]

Serialize this value into the given Serde serializer. Read more

impl Deserialize for Milliseconds
[src]

Deserialize this value from the given Serde deserializer. Read more