Struct sirpent::utils::Milliseconds
[−]
[src]
pub struct Milliseconds { /* fields omitted */ }
Represents a duration in milliseconds.
Methods
impl Milliseconds
[src]
fn new(milliseconds: u64) -> Milliseconds
fn millis(&self) -> u64
Methods from Deref<Target=Duration>
fn as_secs(&self) -> u64
1.3.0
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);
fn subsec_nanos(&self) -> u32
1.3.0
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);
fn checked_add(self, rhs: Duration) -> Option<Duration>
1.16.0
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);
fn checked_sub(self, rhs: Duration) -> Option<Duration>
1.16.0
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);
fn checked_mul(self, rhs: u32) -> Option<Duration>
1.16.0
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);
fn checked_div(self, rhs: u32) -> Option<Duration>
1.16.0
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]
fn eq(&self, __arg_0: &Milliseconds) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Milliseconds) -> bool
This method tests for !=
.
impl Clone for Milliseconds
[src]
fn clone(&self) -> Milliseconds
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Copy for Milliseconds
[src]
impl Debug for Milliseconds
[src]
impl Deref for Milliseconds
[src]
type Target = Duration
The resulting type after dereferencing
fn deref(&self) -> &Self::Target
The method called to dereference a value
impl Into<Duration> for Milliseconds
[src]
impl Serialize for Milliseconds
[src]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer
Serialize this value into the given Serde serializer. Read more
impl Deserialize for Milliseconds
[src]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: Deserializer
Deserialize this value from the given Serde deserializer. Read more