Struct junction_api::Duration
source · pub struct Duration(/* private fields */);
Expand description
A wrapper around std::time::Duration that serializes to and from a f64 number of seconds.
Implementations§
source§impl Duration
impl Duration
sourcepub fn from_secs(val: u64) -> Self
pub fn from_secs(val: u64) -> Self
Create a new Duration
from a whole number of seconds. See
Duration::from_secs.
sourcepub fn from_millis(val: u64) -> Self
pub fn from_millis(val: u64) -> Self
Create a new Duration
from a whole number of milliseconds. See
Duration::from_millis.
sourcepub fn from_micros(val: u64) -> Self
pub fn from_micros(val: u64) -> Self
Create a new Duration
from a whole number of microseconds. See
Duration::from_micros.
sourcepub fn from_secs_f32(val: f32) -> Self
pub fn from_secs_f32(val: f32) -> Self
Create a new Duration
from a floating point number of seconds. See
Duration::from_secs_f32.
sourcepub fn from_secs_f64(val: f64) -> Self
pub fn from_secs_f64(val: f64) -> Self
Create a new Duration
from a floating point number of seconds. See
Duration::from_secs_f64.
Methods from Deref<Target = StdDuration>§
pub const SECOND: Duration = _
pub const MILLISECOND: Duration = _
pub const MICROSECOND: Duration = _
pub const NANOSECOND: Duration = _
pub const ZERO: Duration = _
pub const MAX: Duration = _
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
including the fractional part, use as_secs_f64
or as_secs_f32
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 includes 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 includes 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);
sourcepub fn as_millis_f64(&self) -> f64
🔬This is a nightly-only experimental API. (duration_millis_float
)
pub fn as_millis_f64(&self) -> f64
duration_millis_float
)Returns the number of milliseconds contained by this Duration
as f64
.
The returned value includes the fractional (nanosecond) part of the duration.
§Examples
#![feature(duration_millis_float)]
use std::time::Duration;
let dur = Duration::new(2, 345_678_000);
assert_eq!(dur.as_millis_f64(), 2345.678);
sourcepub fn as_millis_f32(&self) -> f32
🔬This is a nightly-only experimental API. (duration_millis_float
)
pub fn as_millis_f32(&self) -> f32
duration_millis_float
)Returns the number of milliseconds contained by this Duration
as f32
.
The returned value includes the fractional (nanosecond) part of the duration.
§Examples
#![feature(duration_millis_float)]
use std::time::Duration;
let dur = Duration::new(2, 345_678_000);
assert_eq!(dur.as_millis_f32(), 2345.678);
Trait Implementations§
source§impl AsRef<Duration> for Duration
impl AsRef<Duration> for Duration
source§fn as_ref(&self) -> &StdDuration
fn as_ref(&self) -> &StdDuration
source§impl<'de> Deserialize<'de> for Duration
impl<'de> Deserialize<'de> for Duration
source§fn deserialize<D>(deserializer: D) -> Result<Duration, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Duration, D::Error>where
D: Deserializer<'de>,
source§impl From<Duration> for Duration
impl From<Duration> for Duration
source§fn from(duration: StdDuration) -> Self
fn from(duration: StdDuration) -> Self
impl Copy for Duration
impl Eq for Duration
impl StructuralPartialEq for Duration
Auto Trait Implementations§
impl Freeze for Duration
impl RefUnwindSafe for Duration
impl Send for Duration
impl Sync for Duration
impl Unpin for Duration
impl UnwindSafe for Duration
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request