Struct futures_time::time::Duration
source · [−]pub struct Duration(_);
Expand description
A Duration type to represent a span of time, typically used for system timeouts.
This type wraps std::time::Duration
so we can implement traits on it
without coherence issues, just like if we were implementing this in the
stdlib.
Implementations
sourceimpl Duration
impl Duration
sourcepub fn new(secs: u64, nanos: u32) -> Duration
pub fn new(secs: u64, nanos: u32) -> Duration
Creates a new Duration
from the specified number of whole seconds and
additional nanoseconds.
sourcepub fn from_secs(secs: u64) -> Duration
pub fn from_secs(secs: u64) -> Duration
Creates a new Duration
from the specified number of whole seconds.
sourcepub fn from_millis(millis: u64) -> Self
pub fn from_millis(millis: u64) -> Self
Creates a new Duration
from the specified number of milliseconds.
sourcepub fn from_micros(micros: u64) -> Self
pub fn from_micros(micros: u64) -> Self
Creates a new Duration
from the specified number of microseconds.
sourcepub fn from_secs_f64(secs: f64) -> Duration
pub fn from_secs_f64(secs: f64) -> Duration
Creates a new Duration
from the specified number of seconds represented
as f64
.
Panics
This constructor will panic if secs
is not finite, negative or overflows Duration
.
Examples
use futures_time::time::Duration;
let dur = Duration::from_secs_f64(2.7);
assert_eq!(dur, Duration::new(2, 700_000_000));
sourcepub fn from_secs_f32(secs: f32) -> Duration
pub fn from_secs_f32(secs: f32) -> Duration
Creates a new Duration
from the specified number of seconds represented
as f32
.
Panics
This constructor will panic if secs
is not finite, negative or overflows Duration
.
Methods from Deref<Target = Duration>
pub const SECOND: Duration = Duration::from_secs(1)
pub const MILLISECOND: Duration = Duration::from_millis(1)
pub const MICROSECOND: Duration = Duration::from_micros(1)
pub const NANOSECOND: Duration = Duration::from_nanos(1)
pub const ZERO: Duration = Duration::from_nanos(0)
pub const MAX: Duration = Duration::new(u64::MAX, NANOS_PER_SEC - 1)
1.53.0 · sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
Returns true if this Duration
spans no time.
Examples
use std::time::Duration;
assert!(Duration::ZERO.is_zero());
assert!(Duration::new(0, 0).is_zero());
assert!(Duration::from_nanos(0).is_zero());
assert!(Duration::from_secs(0).is_zero());
assert!(!Duration::new(1, 1).is_zero());
assert!(!Duration::from_nanos(1).is_zero());
assert!(!Duration::from_secs(1).is_zero());
1.3.0 · sourcepub fn as_secs(&self) -> u64
pub fn as_secs(&self) -> u64
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 std::time::Duration;
let duration = Duration::new(5, 730023852);
assert_eq!(duration.as_secs(), 5);
To determine the total number of seconds represented by the Duration
,
use as_secs
in combination with subsec_nanos
:
use std::time::Duration;
let duration = Duration::new(5, 730023852);
assert_eq!(5.730023852,
duration.as_secs() as f64
+ duration.subsec_nanos() as f64 * 1e-9);
1.27.0 · sourcepub fn subsec_millis(&self) -> u32
pub fn subsec_millis(&self) -> u32
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 std::time::Duration;
let duration = Duration::from_millis(5432);
assert_eq!(duration.as_secs(), 5);
assert_eq!(duration.subsec_millis(), 432);
1.27.0 · sourcepub fn subsec_micros(&self) -> u32
pub fn subsec_micros(&self) -> u32
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 std::time::Duration;
let duration = Duration::from_micros(1_234_567);
assert_eq!(duration.as_secs(), 1);
assert_eq!(duration.subsec_micros(), 234_567);
1.3.0 · sourcepub fn subsec_nanos(&self) -> u32
pub fn subsec_nanos(&self) -> u32
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 std::time::Duration;
let duration = Duration::from_millis(5010);
assert_eq!(duration.as_secs(), 5);
assert_eq!(duration.subsec_nanos(), 10_000_000);
1.33.0 · sourcepub fn as_millis(&self) -> u128
pub fn as_millis(&self) -> u128
Returns the total number of whole milliseconds contained by this Duration
.
Examples
use std::time::Duration;
let duration = Duration::new(5, 730023852);
assert_eq!(duration.as_millis(), 5730);
1.33.0 · sourcepub fn as_micros(&self) -> u128
pub fn as_micros(&self) -> u128
Returns the total number of whole microseconds contained by this Duration
.
Examples
use std::time::Duration;
let duration = Duration::new(5, 730023852);
assert_eq!(duration.as_micros(), 5730023);
1.33.0 · sourcepub fn as_nanos(&self) -> u128
pub fn as_nanos(&self) -> u128
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);
1.38.0 · sourcepub fn as_secs_f64(&self) -> f64
pub fn as_secs_f64(&self) -> f64
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 std::time::Duration;
let dur = Duration::new(2, 700_000_000);
assert_eq!(dur.as_secs_f64(), 2.7);
1.38.0 · sourcepub fn as_secs_f32(&self) -> f32
pub fn as_secs_f32(&self) -> f32
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 std::time::Duration;
let dur = Duration::new(2, 700_000_000);
assert_eq!(dur.as_secs_f32(), 2.7);
Trait Implementations
sourceimpl AddAssign<Duration> for Duration
impl AddAssign<Duration> for Duration
sourcefn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
Performs the +=
operation. Read more
sourceimpl AddAssign<Duration> for Instant
impl AddAssign<Duration> for Instant
sourcefn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
Performs the +=
operation. Read more
sourceimpl IntoFuture for Duration
impl IntoFuture for Duration
type IntoFuture = Sleep
type IntoFuture = Sleep
Which kind of future are we turning this into?
sourcefn into_future(self) -> Self::IntoFuture
fn into_future(self) -> Self::IntoFuture
Creates a future from a value. Read more
sourceimpl IntoStream for Duration
impl IntoStream for Duration
type IntoStream = Interval
type IntoStream = Interval
Which kind of stream are we turning this into?
sourcefn into_stream(self) -> Self::IntoStream
fn into_stream(self) -> Self::IntoStream
Creates a stream from a value.
sourceimpl Ord for Duration
impl Ord for Duration
sourceimpl PartialOrd<Duration> for Duration
impl PartialOrd<Duration> for Duration
sourcefn partial_cmp(&self, other: &Duration) -> Option<Ordering>
fn partial_cmp(&self, other: &Duration) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl SubAssign<Duration> for Duration
impl SubAssign<Duration> for Duration
sourcefn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
Performs the -=
operation. Read more
sourceimpl SubAssign<Duration> for Instant
impl SubAssign<Duration> for Instant
sourcefn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
Performs the -=
operation. Read more
impl Copy for Duration
impl Eq for Duration
impl StructuralEq for Duration
impl StructuralPartialEq for Duration
Auto Trait Implementations
impl RefUnwindSafe for Duration
impl Send for Duration
impl Sync for Duration
impl Unpin for Duration
impl UnwindSafe for Duration
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more