pub struct FloatDuration { /* private fields */ }Expand description
A time duration stored as a floating point quantity.
Unlike std::time::Duration or chrono::Duration, FloatDuration
aims to be convenient and fast to use in simulation and mathematical expressions
rather than to behave like a calendar or perfectly
accurately represent precise time scales.
Internally, a FloatDuration stores a single f64 number of floating-point seconds,
thus it is only as precise as the f64 type.
Implementations§
Source§impl FloatDuration
impl FloatDuration
Sourcepub fn years(years: f64) -> FloatDuration
pub fn years(years: f64) -> FloatDuration
Create a new FloatDuration representing a number of years.
float_duration considers one year to be exactly 365 days, with
no consideration of leap years.
Sourcepub fn days(days: f64) -> FloatDuration
pub fn days(days: f64) -> FloatDuration
Create a new FloatDuration representing a number of days.
Sourcepub fn hours(hours: f64) -> FloatDuration
pub fn hours(hours: f64) -> FloatDuration
Create a new FloatDuration representing a number of hours.
Sourcepub fn minutes(mins: f64) -> FloatDuration
pub fn minutes(mins: f64) -> FloatDuration
Create a new FloatDuration representing a number of minutes.
Sourcepub fn seconds(secs: f64) -> FloatDuration
pub fn seconds(secs: f64) -> FloatDuration
Create a new FloatDuration representing a number of seconds.
Sourcepub fn milliseconds(millis: f64) -> FloatDuration
pub fn milliseconds(millis: f64) -> FloatDuration
Create a new FloatDuration representing a number of milliseconds.
Sourcepub fn microseconds(micros: f64) -> FloatDuration
pub fn microseconds(micros: f64) -> FloatDuration
Create a new FloatDuration representing a number of microseconds.
Sourcepub fn nanoseconds(nanos: f64) -> FloatDuration
pub fn nanoseconds(nanos: f64) -> FloatDuration
Create a new FloatDuration representing a number of nanoseconds.
Sourcepub fn as_years(&self) -> f64
pub fn as_years(&self) -> f64
Return the total number of fractional years represented by the FloatDuration.
float_duration considers one year to be exactly 365 days, with
no consideration of leap years.
Sourcepub fn as_days(&self) -> f64
pub fn as_days(&self) -> f64
Return the total number of fractional days represented by the FloatDuration.
Sourcepub fn as_hours(&self) -> f64
pub fn as_hours(&self) -> f64
Return the total number of fractional hours represented by the FloatDuration.
Sourcepub fn as_minutes(&self) -> f64
pub fn as_minutes(&self) -> f64
Return the total number of fractional minutes represented by the FloatDuration.
Sourcepub fn as_seconds(&self) -> f64
pub fn as_seconds(&self) -> f64
Return the total number of fractional seconds represented by the FloatDuration.
Sourcepub fn as_milliseconds(&self) -> f64
pub fn as_milliseconds(&self) -> f64
Return the total number of fractional milliseconds represented by the FloatDuration.
Sourcepub fn as_microseconds(&self) -> f64
pub fn as_microseconds(&self) -> f64
Return the total number of fractional microseconds represented by the FloatDuration.
Sourcepub fn as_nanoseconds(&self) -> f64
pub fn as_nanoseconds(&self) -> f64
Return the total number of fractional nanoseconds represented by the FloatDuration.
Sourcepub fn abs(self) -> FloatDuration
pub fn abs(self) -> FloatDuration
Compute the absolute value of this duration.
Sourcepub fn zero() -> FloatDuration
pub fn zero() -> FloatDuration
Return a new FloatDuration that represents zero elapsed time.
Sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
Returns true is this duration represents zero elapsed time (equals FloatDuration::zero()).
Sourcepub fn is_positive(&self) -> bool
pub fn is_positive(&self) -> bool
Returns true if the FloatDuration holds a positive amount of time.
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Returns true if the FloatDuration holds a negative amount of time.
Sourcepub fn signum(&self) -> f64
pub fn signum(&self) -> f64
Return a number that represents the sign of self.
- 1.0 if the value is positive,
+0.0orINFINITY - -1.0 if the value is negative,
-0.0orNEG_INFINITY NANif the value isNAN
Sourcepub fn max(self, other: FloatDuration) -> FloatDuration
pub fn max(self, other: FloatDuration) -> FloatDuration
Return the maximum of two durations.
Sourcepub fn min(self, other: FloatDuration) -> FloatDuration
pub fn min(self, other: FloatDuration) -> FloatDuration
Return the minimum of two durations.
Sourcepub fn min_value() -> FloatDuration
pub fn min_value() -> FloatDuration
Return a new FloatDuration with the minimum possible value.
Sourcepub fn max_value() -> FloatDuration
pub fn max_value() -> FloatDuration
Return a new FloatDuration with the maximum possible value.
Sourcepub fn to_std(&self) -> Result<Duration, OutOfRangeError>
pub fn to_std(&self) -> Result<Duration, OutOfRangeError>
Create a std::time::Duration object from a FloatDuration.
§Errors
std::time::Duration does not support negative values or seconds
greater than std::u64::MAX. This function will return a
DurationError::StdOutOfRange if the FloatDuration value is outside
of either of those bounds.
Sourcepub fn from_std(duration: Duration) -> FloatDuration
pub fn from_std(duration: Duration) -> FloatDuration
Create a FloatDuration object from a std::time::Duration.
Equivalent to using FloatDuration::from(duration)
Source§impl FloatDuration
impl FloatDuration
Sourcepub fn to_chrono(&self) -> Result<Duration, OutOfRangeError>
pub fn to_chrono(&self) -> Result<Duration, OutOfRangeError>
Create a chrono::Duration object from a FloatDuration.
§Errors
Presently, the conversion to chrono::Duration first goes through
std::time::Duration and return an error if to_std returns an error.
Sourcepub fn from_chrono(duration: Duration) -> FloatDuration
pub fn from_chrono(duration: Duration) -> FloatDuration
Create a FloatDuration object from a chrono::Duration.
chrono::Duration does not provide a way to access sub-millisecond
precision if the duration is too large to be entirely represented as a single
value. Thus, if the absolute value of the total number of nanoseconds is
greater than i64::MAX, only millisecond precision will be captured.
Equivalent to using FloatDuration::from(duration)
Trait Implementations§
Source§impl Add for FloatDuration
impl Add for FloatDuration
Source§type Output = FloatDuration
type Output = FloatDuration
+ operator.Source§fn add(self, rhs: FloatDuration) -> FloatDuration
fn add(self, rhs: FloatDuration) -> FloatDuration
+ operation. Read moreSource§impl AddAssign for FloatDuration
impl AddAssign for FloatDuration
Source§fn add_assign(&mut self, rhs: FloatDuration)
fn add_assign(&mut self, rhs: FloatDuration)
+= operation. Read moreSource§impl ApproxEq for FloatDuration
Available on crate feature approx only.
impl ApproxEq for FloatDuration
approx only.Source§fn default_epsilon() -> f64
fn default_epsilon() -> f64
Source§fn default_max_relative() -> f64
fn default_max_relative() -> f64
Source§fn default_max_ulps() -> u32
fn default_max_ulps() -> u32
Source§fn relative_eq(
&self,
other: &FloatDuration,
epsilon: f64,
max_relative: f64,
) -> bool
fn relative_eq( &self, other: &FloatDuration, epsilon: f64, max_relative: f64, ) -> bool
Source§fn ulps_eq(&self, other: &FloatDuration, epsilon: f64, max_ulps: u32) -> bool
fn ulps_eq(&self, other: &FloatDuration, epsilon: f64, max_ulps: u32) -> bool
Source§impl Clone for FloatDuration
impl Clone for FloatDuration
Source§fn clone(&self) -> FloatDuration
fn clone(&self) -> FloatDuration
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FloatDuration
impl Debug for FloatDuration
Source§impl Default for FloatDuration
impl Default for FloatDuration
Source§fn default() -> FloatDuration
fn default() -> FloatDuration
Source§impl<'de> Deserialize<'de> for FloatDuration
Available on crate feature serde only.
impl<'de> Deserialize<'de> for FloatDuration
serde only.Source§fn 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>,
Source§impl Display for FloatDuration
impl Display for FloatDuration
Source§impl Div<f64> for FloatDuration
impl Div<f64> for FloatDuration
Source§type Output = FloatDuration
type Output = FloatDuration
/ operator.Source§impl Div for FloatDuration
impl Div for FloatDuration
Source§impl DivAssign<f64> for FloatDuration
impl DivAssign<f64> for FloatDuration
Source§fn div_assign(&mut self, rhs: f64)
fn div_assign(&mut self, rhs: f64)
/= operation. Read moreSource§impl From<Duration> for FloatDuration
impl From<Duration> for FloatDuration
Source§fn from(from: Duration) -> FloatDuration
fn from(from: Duration) -> FloatDuration
Source§impl From<TimeDelta> for FloatDuration
Available on crate feature chrono only.
impl From<TimeDelta> for FloatDuration
chrono only.Source§fn from(from: Duration) -> FloatDuration
fn from(from: Duration) -> FloatDuration
Source§impl FromDuration<Duration> for FloatDuration
impl FromDuration<Duration> for FloatDuration
Source§impl FromDuration<FloatDuration> for Duration
impl FromDuration<FloatDuration> for Duration
type Error = OutOfRangeError
Source§fn from_duration(from: FloatDuration) -> Result<Duration, OutOfRangeError>
fn from_duration(from: FloatDuration) -> Result<Duration, OutOfRangeError>
from into a Self object.Source§impl FromDuration<FloatDuration> for Duration
Available on crate feature chrono only.
impl FromDuration<FloatDuration> for Duration
chrono only.type Error = OutOfRangeError
Source§fn from_duration(from: FloatDuration) -> Result<Duration, OutOfRangeError>
fn from_duration(from: FloatDuration) -> Result<Duration, OutOfRangeError>
from into a Self object.Source§impl FromDuration<TimeDelta> for FloatDuration
Available on crate feature chrono only.
impl FromDuration<TimeDelta> for FloatDuration
chrono only.Source§impl Mul<FloatDuration> for f64
impl Mul<FloatDuration> for f64
Source§type Output = FloatDuration
type Output = FloatDuration
* operator.Source§fn mul(self, rhs: FloatDuration) -> FloatDuration
fn mul(self, rhs: FloatDuration) -> FloatDuration
* operation. Read moreSource§impl Mul<f64> for FloatDuration
impl Mul<f64> for FloatDuration
Source§type Output = FloatDuration
type Output = FloatDuration
* operator.Source§impl MulAssign<f64> for FloatDuration
impl MulAssign<f64> for FloatDuration
Source§fn mul_assign(&mut self, rhs: f64)
fn mul_assign(&mut self, rhs: f64)
*= operation. Read moreSource§impl Neg for FloatDuration
impl Neg for FloatDuration
Source§type Output = FloatDuration
type Output = FloatDuration
- operator.Source§fn neg(self) -> FloatDuration
fn neg(self) -> FloatDuration
- operation. Read moreSource§impl PartialEq for FloatDuration
impl PartialEq for FloatDuration
Source§impl PartialOrd for FloatDuration
impl PartialOrd for FloatDuration
Source§impl Serialize for FloatDuration
Available on crate feature serde only.
impl Serialize for FloatDuration
serde only.Source§impl Sub for FloatDuration
impl Sub for FloatDuration
Source§type Output = FloatDuration
type Output = FloatDuration
- operator.Source§fn sub(self, rhs: FloatDuration) -> FloatDuration
fn sub(self, rhs: FloatDuration) -> FloatDuration
- operation. Read moreSource§impl SubAssign for FloatDuration
impl SubAssign for FloatDuration
Source§fn sub_assign(&mut self, rhs: FloatDuration)
fn sub_assign(&mut self, rhs: FloatDuration)
-= operation. Read moreSource§impl<'a> Sum<&'a FloatDuration> for FloatDuration
impl<'a> Sum<&'a FloatDuration> for FloatDuration
Source§fn sum<I>(iter: I) -> FloatDurationwhere
I: Iterator<Item = &'a FloatDuration>,
fn sum<I>(iter: I) -> FloatDurationwhere
I: Iterator<Item = &'a FloatDuration>,
Self from the elements by “summing up”
the items.Source§impl Sum for FloatDuration
impl Sum for FloatDuration
Source§fn sum<I>(iter: I) -> FloatDurationwhere
I: Iterator<Item = FloatDuration>,
fn sum<I>(iter: I) -> FloatDurationwhere
I: Iterator<Item = FloatDuration>,
Self from the elements by “summing up”
the items.impl Copy for FloatDuration
impl StructuralPartialEq for FloatDuration
Auto Trait Implementations§
impl Freeze for FloatDuration
impl RefUnwindSafe for FloatDuration
impl Send for FloatDuration
impl Sync for FloatDuration
impl Unpin for FloatDuration
impl UnwindSafe for FloatDuration
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, U> IntoDuration<U> for Twhere
U: FromDuration<T>,
impl<T, U> IntoDuration<U> for Twhere
U: FromDuration<T>,
type Error = <U as FromDuration<T>>::Error
Source§fn into_duration(self) -> Result<U, <U as FromDuration<T>>::Error>
fn into_duration(self) -> Result<U, <U as FromDuration<T>>::Error>
self into a T object.