Struct r3::time::Duration [−][src]
#[repr(transparent)]pub struct Duration { /* fields omitted */ }
Expand description
Represents a signed time span used by the API surface of the R3 RTOS.
Duration
is backed by i32
and can represent the range
[-35′47.483648″, +35′47.483647″] with microsecond precision.
Implementations
Construct a new Duration
from the specified number of microseconds.
Construct a new Duration
from the specified number of milliseconds.
Pancis if millis
overflows the representable range of Duration
.
Construct a new Duration
from the specified number of seconds.
Pancis if secs
overflows the representable range of Duration
.
Get the total number of whole microseconds contained by this Duration
.
Get the total number of whole milliseconds contained by this Duration
.
Get the total number of whole seconds contained by this Duration
.
Get the total number of seconds contained by this Duration
as f64
.
Examples
use r3::time::Duration;
let dur = Duration::from_micros(1_201_250_000);
assert_eq!(dur.as_secs_f64(), 1201.25);
Get the total number of seconds contained by this Duration
as f32
.
Examples
use r3::time::Duration;
let dur = Duration::from_micros(1_201_250_000);
assert_eq!(dur.as_secs_f32(), 1201.25);
Return true
if and only if self
is positive.
Return true
if and only if self
is negative.
Multiply self
by the specified value, returning None
if the result
overflows.
Divide self
by the specified value, returning None
if the result
overflows or other
is zero.
Calculate the absolute value of self
, returning None
if
self == MIN
.
Add the specified value to self
, returning None
if the result
overflows.
Subtract the specified value from self
, returning None
if the result
overflows.
Trait Implementations
Perform a checked addition, panicking on overflow.
Advance the time by duration
in place.
Perform a checked division, panicking on overflow or when rhs
is zero.
Perform a checked multiplication, panicking on overflow.
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Perform a checked subtraction, panicking on overflow.
Put back the time by duration
in place.
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.
Try to construct a Duration
from the specified chrono::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::Duration as ChronoDuration;
use r3::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.