#[repr(transparent)]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§
source§impl Duration
impl Duration
sourcepub const fn from_micros(micros: i32) -> Self
pub const fn from_micros(micros: i32) -> Self
Construct a new Duration
from the specified number of microseconds.
sourcepub const fn from_millis(millis: i32) -> Self
pub const fn from_millis(millis: i32) -> Self
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) -> Self
pub const fn from_secs(secs: i32) -> Self
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<Self>
pub const fn checked_mul(self, other: i32) -> Option<Self>
Multiply self
by the specified value, returning None
if the result
overflows.
sourcepub const fn checked_div(self, other: i32) -> Option<Self>
pub const fn checked_div(self, other: i32) -> Option<Self>
Divide self
by the specified value, returning None
if the result
overflows or other
is zero.
sourcepub const fn checked_abs(self) -> Option<Self>
pub const fn checked_abs(self) -> Option<Self>
Calculate the absolute value of self
, returning None
if
self == MIN
.
sourcepub const fn checked_add(self, other: Self) -> Option<Self>
pub const fn checked_add(self, other: Self) -> Option<Self>
Add the specified value to self
, returning None
if the result
overflows.
sourcepub const fn checked_sub(self, other: Self) -> Option<Self>
pub const fn checked_sub(self, other: Self) -> Option<Self>
Subtract the specified value from self
, returning None
if the result
overflows.
Trait Implementations§
source§impl AddAssign<Duration> for Duration
impl AddAssign<Duration> for Duration
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Perform a checked addition, panicking on overflow.
source§impl AddAssign<Duration> for Time
impl AddAssign<Duration> for Time
source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
Advance the time by duration
in place.
source§impl DivAssign<i32> for Duration
impl DivAssign<i32> for Duration
source§fn 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.
source§impl From<Duration> for Duration
impl From<Duration> for Duration
source§fn from(value: Duration) -> Self
fn from(value: Duration) -> Self
Construct a chrono_0p4::Duration
from the specified Duration
.
Examples
use chrono_0p4::Duration as ChronoDuration;
use r3_core::time::Duration as OsDuration;
assert_eq!(
ChronoDuration::from(OsDuration::from_micros(123_456)),
ChronoDuration::microseconds(123_456),
);
source§impl MulAssign<i32> for Duration
impl MulAssign<i32> for Duration
source§fn mul_assign(&mut self, rhs: i32)
fn mul_assign(&mut self, rhs: i32)
Perform a checked multiplication, panicking on overflow.
source§impl Ord for Duration
impl Ord for Duration
source§impl PartialEq<Duration> for Duration
impl PartialEq<Duration> for Duration
source§impl PartialOrd<Duration> for Duration
impl PartialOrd<Duration> for Duration
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl SubAssign<Duration> for Duration
impl SubAssign<Duration> for Duration
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Perform a checked subtraction, panicking on overflow.
source§impl SubAssign<Duration> for Time
impl SubAssign<Duration> for Time
source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
Put back the time by duration
in place.
source§impl TryFrom<Duration> for Duration
impl TryFrom<Duration> for Duration
source§fn try_from(value: Duration) -> Result<Self, Self::Error>
fn try_from(value: Duration) -> Result<Self, Self::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.
§type Error = TryFromDurationError
type Error = TryFromDurationError
source§impl TryFrom<Duration> for Duration
impl TryFrom<Duration> for Duration
source§fn try_from(value: Duration) -> Result<Self, Self::Error>
fn try_from(value: Duration) -> Result<Self, Self::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()
);