Struct r3_core::time::Duration

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

source

pub const ZERO: Self = _

An empty interval.

source

pub const MAX: Self = _

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

source

pub const MIN: Self = _

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

source

pub const fn from_micros(micros: i32) -> Self

Construct a new Duration from the specified number of microseconds.

source

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.

source

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.

source

pub const fn as_micros(self) -> i32

Get the total number of whole microseconds contained by this Duration.

source

pub const fn as_millis(self) -> i32

Get the total number of whole milliseconds contained by this Duration.

source

pub const fn as_secs(self) -> i32

Get the total number of whole seconds contained by this Duration.

source

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);
source

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);
source

pub const fn is_positive(self) -> bool

Return true if and only if self is positive.

source

pub const fn is_negative(self) -> bool

Return true if and only if self is negative.

source

pub const fn checked_mul(self, other: i32) -> Option<Self>

Multiply self by the specified value, returning None if the result overflows.

source

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.

source

pub const fn checked_abs(self) -> Option<Self>

Calculate the absolute value of self, returning None if self == MIN.

source

pub const fn checked_add(self, other: Self) -> Option<Self>

Add the specified value to self, returning None if the result overflows.

source

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 Add<Duration> for Duration

source§

fn add(self, rhs: Self) -> Self::Output

Perform a checked addition, panicking on overflow.

§

type Output = Duration

The resulting type after applying the + operator.
source§

impl Add<Duration> for Time

source§

fn add(self, rhs: Duration) -> Self::Output

Advance the time by duration and return the result.

§

type Output = Time

The resulting type after applying the + operator.
source§

impl AddAssign<Duration> for Duration

source§

fn add_assign(&mut self, rhs: Self)

Perform a checked addition, panicking on overflow.

source§

impl AddAssign<Duration> for Time

source§

fn add_assign(&mut self, rhs: Duration)

Advance the time by duration in place.

source§

impl Clone for Duration

source§

fn clone(&self) -> Duration

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Duration

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Duration

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Div<i32> for Duration

source§

fn div(self, rhs: i32) -> Self::Output

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

§

type Output = Duration

The resulting type after applying the / operator.
source§

impl DivAssign<i32> for Duration

source§

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

source§

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 Hash for Duration

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Init for Duration

source§

const INIT: Self = Self::ZERO

The default value.
source§

impl Mul<Duration> for i32

source§

fn mul(self, rhs: Duration) -> Self::Output

Perform a checked multiplication, panicking on overflow.

§

type Output = Duration

The resulting type after applying the * operator.
source§

impl Mul<i32> for Duration

source§

fn mul(self, rhs: i32) -> Self::Output

Perform a checked multiplication, panicking on overflow.

§

type Output = Duration

The resulting type after applying the * operator.
source§

impl MulAssign<i32> for Duration

source§

fn mul_assign(&mut self, rhs: i32)

Perform a checked multiplication, panicking on overflow.

source§

impl Ord for Duration

source§

fn cmp(&self, other: &Duration) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Duration> for Duration

source§

fn eq(&self, other: &Duration) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Duration> for Duration

source§

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

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

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

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub<Duration> for Duration

source§

fn sub(self, rhs: Self) -> Self::Output

Perform a checked subtraction, panicking on overflow.

§

type Output = Duration

The resulting type after applying the - operator.
source§

impl Sub<Duration> for Time

source§

fn sub(self, rhs: Duration) -> Self::Output

Put back the time by duration and return the result.

§

type Output = Time

The resulting type after applying the - operator.
source§

impl SubAssign<Duration> for Duration

source§

fn sub_assign(&mut self, rhs: Self)

Perform a checked subtraction, panicking on overflow.

source§

impl SubAssign<Duration> for Time

source§

fn sub_assign(&mut self, rhs: Duration)

Put back the time by duration in place.

source§

impl<'a> Sum<&'a Duration> for Duration

source§

fn sum<I: Iterator<Item = &'a Duration>>(iter: I) -> Self

Perform a checked summation, panicking on overflow.

source§

impl Sum<Duration> for Duration

source§

fn sum<I: Iterator<Item = Duration>>(iter: I) -> Self

Perform a checked summation, panicking on overflow.

source§

impl TryFrom<Duration> for Duration

source§

fn try_from(value: Duration) -> Result<Self, Self::Error>

Try to construct a core::time::Duration from the specified Duration. Returns an error if the specified Duration represents a negative time span.

§

type Error = TryFromDurationError

The type returned in the event of a conversion error.
source§

impl TryFrom<Duration> for Duration

source§

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

The type returned in the event of a conversion error.
source§

impl TryFrom<Duration> for Duration

source§

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

The type returned in the event of a conversion error.
source§

impl Zeroable for Duration

source§

fn zeroed() -> Self

source§

impl Copy for Duration

source§

impl Eq for Duration

source§

impl StructuralEq for Duration

source§

impl StructuralPartialEq for Duration

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Id for Twhere T: Debug + Copy + Eq + Ord + Hash + Send + Sync + 'static + ?Sized,