#[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
sourceimpl 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
sourceimpl AddAssign<Duration> for Duration
impl AddAssign<Duration> for Duration
sourcefn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
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 From<Duration> for Duration
impl From<Duration> for Duration
sourcefn 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),
);
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
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: Self)
fn sub_assign(&mut self, rhs: Self)
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<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
The type returned in the event of a conversion error.
sourceimpl TryFrom<Duration> for Duration
impl TryFrom<Duration> for Duration
sourcefn 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()
);
type Error = TryFromDurationError
type Error = TryFromDurationError
The type returned in the event of a conversion error.
impl Copy for Duration
impl Eq for Duration
impl StructuralEq for Duration
impl StructuralPartialEq for Duration
impl ZeroInit 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