[−][src]Struct easytime::Duration
A Duration
type to represent a span of time, typically used for system
timeouts.
Each Duration
is composed of a whole number of seconds and a fractional part
represented in nanoseconds. If the underlying system does not support
nanosecond-level precision, APIs binding a system timeout will typically round up
the number of nanoseconds.
Duration
s implement many common traits, including Add
, Sub
, and other
ops
traits.
Examples
use easytime::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(), Some(5)); assert_eq!(five_seconds_and_five_nanos.subsec_nanos(), Some(5)); let ten_millis = Duration::from_millis(10);
Implementations
impl Duration
[src]
pub fn new(secs: u64, nanos: u32) -> Self
[src]
Creates a new Duration
from the specified number of whole seconds and
additional nanoseconds.
If the number of nanoseconds is greater than 1 billion (the number of nanoseconds in a second), then it will carry over into the seconds provided.
Examples
use easytime::Duration; let five_seconds = Duration::new(5, 0);
pub const fn from_secs(secs: u64) -> Self
[src]
Creates a new Duration
from the specified number of whole seconds.
Examples
use easytime::Duration; let duration = Duration::from_secs(5); assert_eq!(Some(5), duration.as_secs()); assert_eq!(Some(0), duration.subsec_nanos());
pub const fn from_millis(millis: u64) -> Self
[src]
Creates a new Duration
from the specified number of milliseconds.
Examples
use easytime::Duration; let duration = Duration::from_millis(2_569); assert_eq!(Some(2), duration.as_secs()); assert_eq!(Some(569_000_000), duration.subsec_nanos());
pub const fn from_micros(micros: u64) -> Self
[src]
Creates a new Duration
from the specified number of microseconds.
Examples
use easytime::Duration; let duration = Duration::from_micros(1_000_002); assert_eq!(Some(1), duration.as_secs()); assert_eq!(Some(2000), duration.subsec_nanos());
pub const fn from_nanos(nanos: u64) -> Self
[src]
Creates a new Duration
from the specified number of nanoseconds.
Examples
use easytime::Duration; let duration = Duration::from_nanos(1_000_000_123); assert_eq!(Some(1), duration.as_secs()); assert_eq!(Some(123), duration.subsec_nanos());
pub const fn as_secs(&self) -> Option<u64>
[src]
Returns the number of whole seconds contained by this Duration
.
The returned value does not include the fractional (nanosecond) part of the
duration, which can be obtained using subsec_nanos
.
Examples
use easytime::Duration; let duration = Duration::new(5, 730_023_852); assert_eq!(duration.as_secs(), Some(5));
pub const fn subsec_millis(&self) -> Option<u32>
[src]
Returns the fractional part of this Duration
, in whole milliseconds.
This method does not return the length of the duration when represented by milliseconds. The returned number always represents a fractional portion of a second (i.e., it is less than one thousand).
Examples
use easytime::Duration; let duration = Duration::from_millis(5_432); assert_eq!(duration.as_secs(), Some(5)); assert_eq!(duration.subsec_millis(), Some(432));
pub const fn subsec_micros(&self) -> Option<u32>
[src]
Returns the fractional part of this Duration
, in whole microseconds.
This method does not return the length of the duration when represented by microseconds. The returned number always represents a fractional portion of a second (i.e., it is less than one million).
Examples
use easytime::Duration; let duration = Duration::from_micros(1_234_567); assert_eq!(duration.as_secs(), Some(1)); assert_eq!(duration.subsec_micros(), Some(234_567));
pub const fn subsec_nanos(&self) -> Option<u32>
[src]
Returns the fractional part of this Duration
, in nanoseconds.
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 easytime::Duration; let duration = Duration::from_millis(5_010); assert_eq!(duration.as_secs(), Some(5)); assert_eq!(duration.subsec_nanos(), Some(10_000_000));
pub const fn as_millis(&self) -> Option<u128>
[src]
Returns the total number of whole milliseconds contained by this Duration
.
Examples
use easytime::Duration; let duration = Duration::new(5, 730_023_852); assert_eq!(duration.as_millis(), Some(5_730));
pub const fn as_micros(&self) -> Option<u128>
[src]
Returns the total number of whole microseconds contained by this Duration
.
Examples
use easytime::Duration; let duration = Duration::new(5, 730_023_852); assert_eq!(duration.as_micros(), Some(5_730_023));
pub const fn as_nanos(&self) -> Option<u128>
[src]
Returns the total number of nanoseconds contained by this Duration
.
Examples
use easytime::Duration; let duration = Duration::new(5, 730_023_852); assert_eq!(duration.as_nanos(), Some(5_730_023_852));
pub fn as_secs_f64(&self) -> Option<f64>
[src]
Returns the number of seconds contained by this Duration
as f64
.
The returned value does include the fractional (nanosecond) part of the duration.
Examples
use easytime::Duration; let dur = Duration::new(2, 700_000_000); assert_eq!(dur.as_secs_f64(), Some(2.7));
pub fn as_secs_f32(&self) -> Option<f32>
[src]
Returns the number of seconds contained by this Duration
as f32
.
The returned value does include the fractional (nanosecond) part of the duration.
Examples
use easytime::Duration; let dur = Duration::new(2, 700_000_000); assert_eq!(dur.as_secs_f32(), Some(2.7));
pub fn from_secs_f64(secs: f64) -> Self
[src]
Creates a new Duration
from the specified number of seconds represented
as f64
.
Examples
use easytime::Duration; let dur = Duration::from_secs_f64(2.7); assert_eq!(dur, Duration::new(2, 700_000_000));
pub fn from_secs_f32(secs: f32) -> Duration
[src]
Creates a new Duration
from the specified number of seconds represented
as f32
.
Examples
use easytime::Duration; let dur = Duration::from_secs_f32(2.7); assert_eq!(dur, Duration::new(2, 700_000_000));
pub fn mul_f64(self, rhs: f64) -> Duration
[src]
Multiplies Duration
by f64
.
Examples
use easytime::Duration; let dur = Duration::new(2, 700_000_000); assert_eq!(dur.mul_f64(3.14), Duration::new(8, 478_000_000)); assert_eq!(dur.mul_f64(3.14e5), Duration::new(847_800, 0));
pub fn mul_f32(self, rhs: f32) -> Duration
[src]
Multiplies Duration
by f32
.
Examples
use easytime::Duration; let dur = Duration::new(2, 700_000_000); // note that due to rounding errors result is slightly different // from 8.478 and 847800.0 assert_eq!(dur.mul_f32(3.14), Duration::new(8, 478_000_640)); assert_eq!(dur.mul_f32(3.14e5), Duration::new(847799, 969_120_256));
pub fn div_f64(self, rhs: f64) -> Duration
[src]
Divide Duration
by f64
.
Examples
use easytime::Duration; let dur = Duration::new(2, 700_000_000); assert_eq!(dur.div_f64(3.14), Duration::new(0, 859_872_611)); // note that truncation is used, not rounding assert_eq!(dur.div_f64(3.14e5), Duration::new(0, 8_598));
pub fn div_f32(self, rhs: f32) -> Duration
[src]
Divide Duration
by f32
.
Examples
use easytime::Duration; let dur = Duration::new(2, 700_000_000); assert_eq!(dur.div_f64(3.14), Duration::new(0, 859_872_611)); // note that truncation is used, not rounding assert_eq!(dur.div_f64(3.14e5), Duration::new(0, 8_598));
pub const fn is_some(&self) -> bool
[src]
Returns true
if into_inner
returns Some
.
Examples
use easytime::Duration; let zero = Duration::new(0, 0); let one_sec = Duration::new(1, 0); assert!((one_sec - zero).is_some()); assert!(!(zero - one_sec).is_some());
pub const fn is_none(&self) -> bool
[src]
Returns true
if into_inner
returns None
.
Examples
use easytime::Duration; let zero = Duration::new(0, 0); let one_sec = Duration::new(1, 0); assert!(!(one_sec - zero).is_none()); assert!((zero - one_sec).is_none());
pub const fn into_inner(self) -> Option<Duration>
[src]
Returns the contained std::time::Duration
or None
.
Examples
use easytime::Duration; let zero = Duration::new(0, 0); let one_sec = Duration::new(1, 0); assert_eq!((one_sec - zero).into_inner(), Some(std::time::Duration::from_secs(1))); assert_eq!((zero - one_sec).into_inner(), None);
pub const fn unwrap_or(self, default: Duration) -> Duration
[src]
Returns the contained std::time::Duration
or a default.
dur.unwrap_or(default)
is equivalent to dur.into_inner().unwrap_or(default)
.
Examples
use easytime::Duration; let zero = Duration::new(0, 0); let one_sec = Duration::new(1, 0); assert_eq!( (one_sec - zero).unwrap_or(std::time::Duration::from_secs(2)), std::time::Duration::from_secs(1) ); assert_eq!( (zero - one_sec).unwrap_or(std::time::Duration::from_secs(2)), std::time::Duration::from_secs(2) );
pub fn unwrap_or_else<F>(self, default: F) -> Duration where
F: FnOnce() -> Duration,
[src]
F: FnOnce() -> Duration,
Returns the contained std::time::Duration
or computes it from a closure.
dur.unwrap_or_else(default)
is equivalent to dur.into_inner().unwrap_or_else(default)
.
Examples
use easytime::Duration; let zero = Duration::new(0, 0); let one_sec = Duration::new(1, 0); assert_eq!( (one_sec - zero).unwrap_or_else(|| std::time::Duration::from_secs(2)), std::time::Duration::from_secs(1) ); assert_eq!( (zero - one_sec).unwrap_or_else(|| std::time::Duration::from_secs(2)), std::time::Duration::from_secs(2) );
Trait Implementations
impl Add<Duration> for Duration
[src]
type Output = Self
The resulting type after applying the +
operator.
pub fn add(self, rhs: Self) -> Self::Output
[src]
impl Add<Duration> for Duration
[src]
type Output = Self
The resulting type after applying the +
operator.
pub fn add(self, rhs: Duration) -> Self::Output
[src]
impl Add<Duration> for Instant
[src]
type Output = Self
The resulting type after applying the +
operator.
pub fn add(self, other: Duration) -> Self::Output
[src]
impl AddAssign<Duration> for Duration
[src]
pub fn add_assign(&mut self, rhs: Self)
[src]
impl AddAssign<Duration> for Duration
[src]
pub fn add_assign(&mut self, rhs: Duration)
[src]
impl AddAssign<Duration> for Instant
[src]
pub fn add_assign(&mut self, other: Duration)
[src]
impl Clone for Duration
[src]
impl Copy for Duration
[src]
impl Debug for Duration
[src]
impl Default for Duration
[src]
impl Div<u32> for Duration
[src]
type Output = Self
The resulting type after applying the /
operator.
pub fn div(self, rhs: u32) -> Self::Output
[src]
impl DivAssign<u32> for Duration
[src]
pub fn div_assign(&mut self, rhs: u32)
[src]
impl Eq for Duration
[src]
impl From<Duration> for Duration
[src]
impl From<Option<Duration>> for Duration
[src]
impl Hash for Duration
[src]
pub fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Mul<Duration> for u32
[src]
type Output = Duration
The resulting type after applying the *
operator.
pub fn mul(self, rhs: Duration) -> Self::Output
[src]
impl Mul<u32> for Duration
[src]
type Output = Self
The resulting type after applying the *
operator.
pub fn mul(self, rhs: u32) -> Self::Output
[src]
impl MulAssign<u32> for Duration
[src]
pub fn mul_assign(&mut self, rhs: u32)
[src]
impl Ord for Duration
[src]
pub fn cmp(&self, other: &Duration) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<Duration> for Duration
[src]
impl PartialEq<Duration> for Duration
[src]
pub fn eq(&self, other: &Duration) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialEq<Duration> for Duration
[src]
pub fn eq(&self, other: &Duration) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<Duration> for Duration
[src]
pub fn partial_cmp(&self, other: &Duration) -> Option<Ordering>
[src]
pub fn lt(&self, other: &Duration) -> bool
[src]
pub fn le(&self, other: &Duration) -> bool
[src]
pub fn gt(&self, other: &Duration) -> bool
[src]
pub fn ge(&self, other: &Duration) -> bool
[src]
impl PartialOrd<Duration> for Duration
[src]
pub fn partial_cmp(&self, other: &Duration) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<Duration> for Duration
[src]
pub fn partial_cmp(&self, other: &Duration) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl StructuralEq for Duration
[src]
impl StructuralPartialEq for Duration
[src]
impl Sub<Duration> for Duration
[src]
type Output = Self
The resulting type after applying the -
operator.
pub fn sub(self, rhs: Self) -> Self::Output
[src]
impl Sub<Duration> for Duration
[src]
type Output = Self
The resulting type after applying the -
operator.
pub fn sub(self, rhs: Duration) -> Self::Output
[src]
impl Sub<Duration> for Instant
[src]
type Output = Self
The resulting type after applying the -
operator.
pub fn sub(self, other: Duration) -> Self::Output
[src]
impl SubAssign<Duration> for Duration
[src]
pub fn sub_assign(&mut self, rhs: Self)
[src]
impl SubAssign<Duration> for Duration
[src]
pub fn sub_assign(&mut self, rhs: Duration)
[src]
impl SubAssign<Duration> for Instant
[src]
pub fn sub_assign(&mut self, other: Duration)
[src]
impl TryFrom<Duration> for Duration
[src]
Auto Trait Implementations
impl RefUnwindSafe for Duration
[src]
impl Send for Duration
[src]
impl Sync for Duration
[src]
impl Unpin for Duration
[src]
impl UnwindSafe for Duration
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,