pub struct Duration(f64);
Expand description
A duration, in seconds. Can be negative.
Tuple Fields
0: f64
Implementations
sourceimpl Duration
impl Duration
pub const ZERO: Duration
pub const EPSILON: Duration
sourcepub fn f64_minutes(mins: f64) -> Duration
pub fn f64_minutes(mins: f64) -> Duration
Creates a duration in minutes.
sourcepub fn milliseconds(value: f64) -> Duration
pub fn milliseconds(value: f64) -> Duration
Creates a duration in milliseconds.
pub const fn const_seconds(value: f64) -> Duration
pub(crate) fn to_u64(self) -> u64
pub(crate) fn from_u64(x: u64) -> Duration
pub fn abs(&self) -> Self
sourcepub fn inner_seconds(self) -> f64
pub fn inner_seconds(self) -> f64
Returns the duration in seconds. Prefer working in typesafe Duration
s.
sourcefn get_parts(self) -> (usize, usize, usize, usize)
fn get_parts(self) -> (usize, usize, usize, usize)
Splits the duration into (hours, minutes, seconds, deciseconds).
sourcepub fn parse(string: &str) -> Result<Duration>
pub fn parse(string: &str) -> Result<Duration>
Parses a duration such as “3:00” to Duration::minutes(3)
.
sourcepub fn epsilon_eq(self, other: Duration) -> bool
pub fn epsilon_eq(self, other: Duration) -> bool
If two durations are within this amount, they’ll print as if they’re the same.
sourcepub fn realtime_elapsed(since: Instant) -> Duration
pub fn realtime_elapsed(since: Instant) -> Duration
Returns the duration elapsed from this moment in real time.
sourcepub fn round_up(self, multiple: Duration) -> Duration
pub fn round_up(self, multiple: Duration) -> Duration
Rounds a duration up to the nearest whole number multiple.
sourcepub fn num_minutes_rounded_up(self) -> usize
pub fn num_minutes_rounded_up(self) -> usize
Returns the duration as a number of minutes, rounded up.
sourcepub fn make_intervals_for_max(
self,
num_labels: usize
) -> (Duration, Vec<Duration>)
pub fn make_intervals_for_max(
self,
num_labels: usize
) -> (Duration, Vec<Duration>)
Returns (rounded max, the boundaries)
sourcepub fn to_rounded_string(self, precision: usize) -> String
pub fn to_rounded_string(self, precision: usize) -> String
Shows only the largest unit (hours, minute, seconds), rounded to precision
decimal points.
use geom::Duration;
assert_eq!(Duration::seconds(3600.0).to_rounded_string(0), "1hr");
assert_eq!(Duration::seconds(3600.0).to_rounded_string(1), "1.0hr");
assert_eq!(Duration::seconds(7800.0).to_rounded_string(0), "2hr");
assert_eq!(Duration::seconds(800.0).to_rounded_string(1), "13.3min");
assert_eq!(Duration::seconds(-800.0).to_rounded_string(1), "-13.3min");
assert_eq!(Duration::seconds(0.0).to_rounded_string(0), "0");
assert_eq!(Duration::seconds(12.5).to_rounded_string(1), "12.5s");
assert_eq!(Duration::seconds(12.5).to_rounded_string(2), "12.50s");
Trait Implementations
sourceimpl AddAssign<Duration> for Duration
impl AddAssign<Duration> for Duration
sourcefn add_assign(&mut self, other: Duration)
fn add_assign(&mut self, other: Duration)
Performs the +=
operation. Read more
sourceimpl AddAssign<Duration> for Time
impl AddAssign<Duration> for Time
sourcefn add_assign(&mut self, other: Duration)
fn add_assign(&mut self, other: Duration)
Performs the +=
operation. Read more
sourceimpl<'de> Deserialize<'de> for Duration
impl<'de> Deserialize<'de> for Duration
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl HgramValue<Duration> for Duration
impl HgramValue<Duration> for Duration
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, other: Duration)
fn sub_assign(&mut self, other: Duration)
Performs the -=
operation. Read more
impl Copy for Duration
impl Eq for Duration
impl StructuralPartialEq 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 · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more