Struct float_duration::duration::FloatDuration
[−]
[src]
pub struct FloatDuration { /* fields omitted */ }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.
Methods
impl FloatDuration[src]
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.
fn days(days: f64) -> FloatDuration
Create a new FloatDuration representing a number of days.
fn hours(hours: f64) -> FloatDuration
Create a new FloatDuration representing a number of hours.
fn minutes(mins: f64) -> FloatDuration
Create a new FloatDuration representing a number of minutes.
fn seconds(secs: f64) -> FloatDuration
Create a new FloatDuration representing a number of seconds.
fn milliseconds(millis: f64) -> FloatDuration
Create a new FloatDuration representing a number of milliseconds.
fn microseconds(micros: f64) -> FloatDuration
Create a new FloatDuration representing a number of microseconds.
fn nanoseconds(nanos: f64) -> FloatDuration
Create a new FloatDuration representing a number of nanoseconds.
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.
fn as_days(&self) -> f64
Return the total number of fractional days represented by the FloatDuration.
fn as_hours(&self) -> f64
Return the total number of fractional hours represented by the FloatDuration.
fn as_minutes(&self) -> f64
Return the total number of fractional minutes represented by the FloatDuration.
fn as_seconds(&self) -> f64
Return the total number of fractional seconds represented by the FloatDuration.
fn as_milliseconds(&self) -> f64
Return the total number of fractional milliseconds represented by the FloatDuration.
fn as_microseconds(&self) -> f64
Return the total number of fractional microseconds represented by the FloatDuration.
fn as_nanoseconds(&self) -> f64
Return the total number of fractional nanoseconds represented by the FloatDuration.
fn abs(self) -> FloatDuration
Compute the absolute value of this duration.
fn zero() -> FloatDuration
Return a new FloatDuration that represents zero elapsed time.
fn is_zero(&self) -> bool
Returns true is this duration represents zero elapsed time (equals FloatDuration::zero()).
fn is_positive(&self) -> bool
Returns true if the FloatDuration holds a positive amount of time.
fn is_negative(&self) -> bool
Returns true if the FloatDuration holds a negative amount of time.
fn min_value() -> FloatDuration
Return a new FloatDuration with the minimum possible value.
fn max_value() -> FloatDuration
Return a new FloatDuration with the maximum possible value.
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.
fn from_std(duration: Duration) -> FloatDuration
Create a FloatDuration object from a std::time::Duration.
impl FloatDuration[src]
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.
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.
Trait Implementations
impl Debug for FloatDuration[src]
impl Clone for FloatDuration[src]
fn clone(&self) -> FloatDuration
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0
Performs copy-assignment from source. Read more
impl Copy for FloatDuration[src]
impl PartialEq for FloatDuration[src]
fn eq(&self, __arg_0: &FloatDuration) -> bool
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, __arg_0: &FloatDuration) -> bool
This method tests for !=.
impl PartialOrd for FloatDuration[src]
fn partial_cmp(&self, __arg_0: &FloatDuration) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
fn lt(&self, __arg_0: &FloatDuration) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
fn le(&self, __arg_0: &FloatDuration) -> bool
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
fn gt(&self, __arg_0: &FloatDuration) -> bool
This method tests greater than (for self and other) and is used by the > operator. Read more
fn ge(&self, __arg_0: &FloatDuration) -> bool
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
impl Serialize for FloatDuration[src]
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where
S: Serializer,
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<'de> Deserialize<'de> for FloatDuration[src]
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Display for FloatDuration[src]
impl Neg for FloatDuration[src]
type Output = FloatDuration
The resulting type after applying the - operator
fn neg(self) -> FloatDuration
The method for the unary - operator
impl Add<FloatDuration> for FloatDuration[src]
type Output = FloatDuration
The resulting type after applying the + operator
fn add(self, rhs: FloatDuration) -> FloatDuration
The method for the + operator
impl Sub<FloatDuration> for FloatDuration[src]
type Output = FloatDuration
The resulting type after applying the - operator
fn sub(self, rhs: FloatDuration) -> FloatDuration
The method for the - operator
impl Mul<f64> for FloatDuration[src]
type Output = FloatDuration
The resulting type after applying the * operator
fn mul(self, rhs: f64) -> FloatDuration
The method for the * operator
impl Div<f64> for FloatDuration[src]
type Output = FloatDuration
The resulting type after applying the / operator
fn div(self, rhs: f64) -> FloatDuration
The method for the / operator
impl Div<FloatDuration> for FloatDuration[src]
type Output = f64
The resulting type after applying the / operator
fn div(self, rhs: FloatDuration) -> f64
The method for the / operator
impl AddAssign<FloatDuration> for FloatDuration[src]
fn add_assign(&mut self, rhs: FloatDuration)
The method for the += operator
impl SubAssign<FloatDuration> for FloatDuration[src]
fn sub_assign(&mut self, rhs: FloatDuration)
The method for the -= operator
impl MulAssign<f64> for FloatDuration[src]
fn mul_assign(&mut self, rhs: f64)
The method for the *= operator
impl DivAssign<f64> for FloatDuration[src]
fn div_assign(&mut self, rhs: f64)
The method for the /= operator
impl Default for FloatDuration[src]
fn default() -> FloatDuration
Returns the "default value" for a type. Read more
impl ApproxEq for FloatDuration[src]
type Epsilon = f64
Used for specifying relative comparisons.
fn default_epsilon() -> f64
The default tolerance to use when testing values that are close together. Read more
fn default_max_relative() -> f64
The default relative tolerance for testing values that are far-apart. Read more
fn default_max_ulps() -> u32
The default ULPs to tolerate when testing values that are far-apart. Read more
fn relative_eq(
&self,
other: &FloatDuration,
epsilon: f64,
max_relative: f64
) -> bool
&self,
other: &FloatDuration,
epsilon: f64,
max_relative: f64
) -> bool
A test for equality that uses a relative comparison if the values are far apart.
fn ulps_eq(&self, other: &FloatDuration, epsilon: f64, max_ulps: u32) -> bool
A test for equality that uses units in the last place (ULP) if the values are far apart.
fn relative_ne(
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
&self,
other: &Self,
epsilon: Self::Epsilon,
max_relative: Self::Epsilon
) -> bool
The inverse of ApproxEq::relative_eq.
fn ulps_ne(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool
The inverse of ApproxEq::ulps_eq.