Struct r3::time::Duration

source ·
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

An empty interval.

The large representable positive time span (+35′47.483647″).

The large representable negative time span (-35′47.483648″).

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_core::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_core::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.

The resulting type after applying the + operator.

Advance the time by duration and return the result.

The resulting type after applying the + operator.

Perform a checked addition, panicking on overflow.

Advance the time by duration in place.

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more

Perform a checked division, panicking on overflow or when rhs is zero.

The resulting type after applying the / operator.

Perform a checked division, panicking on overflow or when rhs is zero.

Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
The default value.

Perform a checked multiplication, panicking on overflow.

The resulting type after applying the * operator.

Perform a checked multiplication, panicking on overflow.

This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
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
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Perform a checked subtraction, panicking on overflow.

The resulting type after applying the - operator.

Put back the time by duration and return the result.

The resulting type after applying the - operator.

Perform a checked subtraction, panicking on overflow.

Put back the time by duration in place.

Perform a checked summation, panicking on overflow.

Perform a checked summation, panicking on overflow.

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()
);
The type returned in the event of a conversion 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.

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.