pub struct Duration { /* private fields */ }
Expand description
Represents a signed time span used by the API surface of R3-OS.
Duration
is backed by i32
and can represent the range
[-35′47.483648″, +35′47.483647″] with microsecond precision.
Implementations
sourceimpl Duration
impl Duration
sourcepub const MAX: Duration = Duration{ micros: i32::MAX,}
pub const MAX: Duration = Duration{ micros: i32::MAX,}
The large representable positive time span (+35′47.483647″).
sourcepub const MIN: Duration = Duration{ micros: i32::MIN,}
pub const MIN: Duration = Duration{ micros: i32::MIN,}
The large representable negative time span (-35′47.483648″).
sourcepub const fn from_micros(micros: i32) -> Duration
pub const fn from_micros(micros: i32) -> Duration
Construct a new Duration
from the specified number of microseconds.
sourcepub const fn from_millis(millis: i32) -> Duration
pub const fn from_millis(millis: i32) -> Duration
Construct a new Duration
from the specified number of milliseconds.
Pancis if millis
overflows the representable range of Duration
.
sourcepub const fn from_secs(secs: i32) -> Duration
pub const fn from_secs(secs: i32) -> Duration
Construct a new Duration
from the specified number of seconds.
Pancis if secs
overflows the representable range of Duration
.
sourcepub const fn as_micros(self) -> i32
pub const fn as_micros(self) -> i32
Get the total number of whole microseconds contained by this Duration
.
sourcepub const fn as_millis(self) -> i32
pub const fn as_millis(self) -> i32
Get the total number of whole milliseconds contained by this Duration
.
sourcepub const fn as_secs(self) -> i32
pub const fn as_secs(self) -> i32
Get the total number of whole seconds contained by this Duration
.
sourcepub const fn as_secs_f64(self) -> f64
pub const fn as_secs_f64(self) -> f64
Get the total number of seconds contained by this Duration
as f64
.
Examples
use r3_core::time::Duration;
let dur = Duration::from_micros(1_201_250_000);
assert_eq!(dur.as_secs_f64(), 1201.25);
sourcepub const fn as_secs_f32(self) -> f32
pub const fn as_secs_f32(self) -> f32
Get the total number of seconds contained by this Duration
as f32
.
Examples
use r3_core::time::Duration;
let dur = Duration::from_micros(1_201_250_000);
assert_eq!(dur.as_secs_f32(), 1201.25);
sourcepub const fn is_positive(self) -> bool
pub const fn is_positive(self) -> bool
Return true
if and only if self
is positive.
sourcepub const fn is_negative(self) -> bool
pub const fn is_negative(self) -> bool
Return true
if and only if self
is negative.
sourcepub const fn checked_mul(self, other: i32) -> Option<Duration>
pub const fn checked_mul(self, other: i32) -> Option<Duration>
Multiply self
by the specified value, returning None
if the result
overflows.
sourcepub const fn checked_div(self, other: i32) -> Option<Duration>
pub const fn checked_div(self, other: i32) -> Option<Duration>
Divide self
by the specified value, returning None
if the result
overflows or other
is zero.
sourcepub const fn checked_abs(self) -> Option<Duration>
pub const fn checked_abs(self) -> Option<Duration>
Calculate the absolute value of self
, returning None
if
self == MIN
.
sourcepub const fn checked_add(self, other: Duration) -> Option<Duration>
pub const fn checked_add(self, other: Duration) -> Option<Duration>
Add the specified value to self
, returning None
if the result
overflows.
sourcepub const fn checked_sub(self, other: Duration) -> Option<Duration>
pub const fn checked_sub(self, other: Duration) -> Option<Duration>
Subtract the specified value from self
, returning None
if the result
overflows.
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)
Perform a checked addition, panicking on overflow.
sourceimpl AddAssign<Duration> for Time
impl AddAssign<Duration> for Time
sourcefn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
Advance the time by duration
in place.
sourceimpl DivAssign<i32> for Duration
impl DivAssign<i32> for Duration
sourcefn div_assign(&mut self, rhs: i32)
fn div_assign(&mut self, rhs: i32)
Perform a checked division, panicking on overflow or when rhs
is zero.
sourceimpl MulAssign<i32> for Duration
impl MulAssign<i32> for Duration
sourcefn mul_assign(&mut self, rhs: i32)
fn mul_assign(&mut self, rhs: i32)
Perform a checked multiplication, panicking on overflow.
sourceimpl Ord for Duration
impl Ord for Duration
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
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>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresourceimpl SubAssign<Duration> for Duration
impl SubAssign<Duration> for Duration
sourcefn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
Perform a checked subtraction, panicking on overflow.
sourceimpl SubAssign<Duration> for Time
impl SubAssign<Duration> for Time
sourcefn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
Put back the time by duration
in place.
sourceimpl TryFrom<Duration> for Duration
impl TryFrom<Duration> for Duration
sourcefn try_from(
value: Duration
) -> Result<Duration, <Duration as TryFrom<Duration>>::Error>
fn try_from(
value: Duration
) -> Result<Duration, <Duration as TryFrom<Duration>>::Error>
Try to construct a Duration
from the specified chrono_0p4::Duration
.
Returns an error if the specified Duration
overflows the representable
range of the destination type.
The sub-microsecond part is rounded by truncating.
Examples
use chrono_0p4::Duration as ChronoDuration;
use r3_core::time::Duration as OsDuration;
assert_eq!(
OsDuration::try_from(ChronoDuration::nanoseconds(123_456)),
Ok(OsDuration::from_micros(123)),
);
assert_eq!(
OsDuration::try_from(ChronoDuration::nanoseconds(-123_456)),
Ok(OsDuration::from_micros(-123)),
);
assert!(
OsDuration::try_from(ChronoDuration::microseconds(0x100000000))
.is_err()
);
type Error = TryFromDurationError
type Error = TryFromDurationError
sourceimpl TryFrom<Duration> for Duration
impl TryFrom<Duration> for Duration
sourcefn try_from(
value: Duration
) -> Result<Duration, <Duration as TryFrom<Duration>>::Error>
fn try_from(
value: Duration
) -> Result<Duration, <Duration as TryFrom<Duration>>::Error>
Try to construct a Duration
from the specified core::time::Duration
.
Returns an error if the specified Duration
overflows the representable
range of the destination type.
The sub-microsecond part is rounded by truncating.