pub struct Time(_);
Expand description
Represents a time value.
Time encapsulates a time value in a flexible way.
It allows to define a time value either as a number of seconds, milliseconds or microseconds. It also works the other way round: you can read a time value as either a number of seconds, milliseconds or microseconds.
By using such a flexible interface, the API doesn’t impose any fixed type or resolution for time values, and let the user choose its own favorite representation.
Time values support the usual mathematical operations: you can add or subtract two times, multiply or divide a time by a number, compare two times, etc.
Since they represent a time span and not an absolute time value, times can also be negative.
Usage example
let t1 = Time::seconds(0.1);
assert_eq!(t1.as_milliseconds(), 100);
let t2 = Time::milliseconds(30);
assert_eq!(t2.as_microseconds(), 30_000);
let t3 = Time::microseconds(-800_000);
assert_eq!(t3.as_seconds(), -0.8);
See also
Implementations
sourceimpl Time
impl Time
sourcepub const fn milliseconds(milliseconds: i32) -> Self
pub const fn milliseconds(milliseconds: i32) -> Self
Constructs a time value from a number of milliseconds.
sourcepub const fn microseconds(microseconds: i64) -> Self
pub const fn microseconds(microseconds: i64) -> Self
Constructs a time value from a number of microseconds.
sourcepub fn as_seconds(self) -> f32
pub fn as_seconds(self) -> f32
Returns the time value as a number of seconds.
sourcepub fn as_milliseconds(self) -> i32
pub fn as_milliseconds(self) -> i32
Returns the time value as a number of milliseconds.
sourcepub fn as_microseconds(self) -> i64
pub fn as_microseconds(self) -> i64
Returns the time value as a number of microseconds.
Trait Implementations
sourceimpl AddAssign<Time> for Time
impl AddAssign<Time> for Time
sourcefn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moresourceimpl DivAssign<f32> for Time
impl DivAssign<f32> for Time
sourcefn div_assign(&mut self, rhs: f32)
fn div_assign(&mut self, rhs: f32)
Overload of binary /= operator to scale/assign a time value.
sourceimpl DivAssign<i64> for Time
impl DivAssign<i64> for Time
sourcefn div_assign(&mut self, rhs: i64)
fn div_assign(&mut self, rhs: i64)
Overload of binary /= operator to scale/assign a time value.
sourceimpl MulAssign<f32> for Time
impl MulAssign<f32> for Time
sourcefn mul_assign(&mut self, rhs: f32)
fn mul_assign(&mut self, rhs: f32)
Overload of binary *= operator to scale/assign a time value.
sourceimpl MulAssign<i64> for Time
impl MulAssign<i64> for Time
sourcefn mul_assign(&mut self, rhs: i64)
fn mul_assign(&mut self, rhs: i64)
Overload of binary *= operator to scale/assign a time value.
sourceimpl Ord for Time
impl Ord for Time
1.21.0 · sourcefn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 · sourcefn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: Sized + PartialOrd<Self>,
sourceimpl PartialOrd<Time> for Time
impl PartialOrd<Time> for Time
sourcefn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresourceimpl RemAssign<Time> for Time
impl RemAssign<Time> for Time
sourcefn rem_assign(&mut self, rhs: Self)
fn rem_assign(&mut self, rhs: Self)
%=
operation. Read moresourceimpl SubAssign<Time> for Time
impl SubAssign<Time> for Time
sourcefn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read more