FloatDuration

Struct FloatDuration 

Source
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

Source

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.

Source

pub fn days(days: f64) -> FloatDuration

Create a new FloatDuration representing a number of days.

Source

pub fn hours(hours: f64) -> FloatDuration

Create a new FloatDuration representing a number of hours.

Source

pub fn minutes(mins: f64) -> FloatDuration

Create a new FloatDuration representing a number of minutes.

Source

pub fn seconds(secs: f64) -> FloatDuration

Create a new FloatDuration representing a number of seconds.

Source

pub fn milliseconds(millis: f64) -> FloatDuration

Create a new FloatDuration representing a number of milliseconds.

Source

pub fn microseconds(micros: f64) -> FloatDuration

Create a new FloatDuration representing a number of microseconds.

Source

pub fn nanoseconds(nanos: f64) -> FloatDuration

Create a new FloatDuration representing a number of nanoseconds.

Source

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.

Source

pub fn as_days(&self) -> f64

Return the total number of fractional days represented by the FloatDuration.

Source

pub fn as_hours(&self) -> f64

Return the total number of fractional hours represented by the FloatDuration.

Source

pub fn as_minutes(&self) -> f64

Return the total number of fractional minutes represented by the FloatDuration.

Source

pub fn as_seconds(&self) -> f64

Return the total number of fractional seconds represented by the FloatDuration.

Source

pub fn as_milliseconds(&self) -> f64

Return the total number of fractional milliseconds represented by the FloatDuration.

Source

pub fn as_microseconds(&self) -> f64

Return the total number of fractional microseconds represented by the FloatDuration.

Source

pub fn as_nanoseconds(&self) -> f64

Return the total number of fractional nanoseconds represented by the FloatDuration.

Source

pub fn abs(self) -> FloatDuration

Compute the absolute value of this duration.

Source

pub fn zero() -> FloatDuration

Return a new FloatDuration that represents zero elapsed time.

Source

pub fn is_zero(&self) -> bool

Returns true is this duration represents zero elapsed time (equals FloatDuration::zero()).

Source

pub fn is_positive(&self) -> bool

Returns true if the FloatDuration holds a positive amount of time.

Source

pub fn is_negative(&self) -> bool

Returns true if the FloatDuration holds a negative amount of time.

Source

pub fn signum(&self) -> f64

Return a number that represents the sign of self.

  • 1.0 if the value is positive, +0.0 or INFINITY
  • -1.0 if the value is negative, -0.0 or NEG_INFINITY
  • NAN if the value is NAN
Source

pub fn max(self, other: FloatDuration) -> FloatDuration

Return the maximum of two durations.

Source

pub fn min(self, other: FloatDuration) -> FloatDuration

Return the minimum of two durations.

Source

pub fn min_value() -> FloatDuration

Return a new FloatDuration with the minimum possible value.

Source

pub fn max_value() -> FloatDuration

Return a new FloatDuration with the maximum possible value.

Source

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.

Source

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

Source

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.

Source

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

Source§

type Output = FloatDuration

The resulting type after applying the + operator.
Source§

fn add(self, rhs: FloatDuration) -> FloatDuration

Performs the + operation. Read more
Source§

impl AddAssign for FloatDuration

Source§

fn add_assign(&mut self, rhs: FloatDuration)

Performs the += operation. Read more
Source§

impl ApproxEq for FloatDuration

Available on crate feature approx only.
Source§

type Epsilon = f64

Used for specifying relative comparisons.
Source§

fn default_epsilon() -> f64

The default tolerance to use when testing values that are close together. Read more
Source§

fn default_max_relative() -> f64

The default relative tolerance for testing values that are far-apart. Read more
Source§

fn default_max_ulps() -> u32

The default ULPs to tolerate when testing values that are far-apart. Read more
Source§

fn relative_eq( &self, other: &FloatDuration, epsilon: f64, max_relative: f64, ) -> bool

A test for equality that uses a relative comparison if the values are far apart.
Source§

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.
Source§

fn relative_ne( &self, other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool

The inverse of ApproxEq::relative_eq.
Source§

fn ulps_ne(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool

The inverse of ApproxEq::ulps_eq.
Source§

impl Clone for FloatDuration

Source§

fn clone(&self) -> FloatDuration

Returns a duplicate 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 FloatDuration

Source§

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

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

impl Default for FloatDuration

Source§

fn default() -> FloatDuration

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

impl<'de> Deserialize<'de> for FloatDuration

Available on crate feature serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for FloatDuration

Source§

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

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

impl Div<f64> for FloatDuration

Source§

type Output = FloatDuration

The resulting type after applying the / operator.
Source§

fn div(self, rhs: f64) -> FloatDuration

Performs the / operation. Read more
Source§

impl Div for FloatDuration

Source§

type Output = f64

The resulting type after applying the / operator.
Source§

fn div(self, rhs: FloatDuration) -> f64

Performs the / operation. Read more
Source§

impl DivAssign<f64> for FloatDuration

Source§

fn div_assign(&mut self, rhs: f64)

Performs the /= operation. Read more
Source§

impl From<Duration> for FloatDuration

Source§

fn from(from: Duration) -> FloatDuration

Converts to this type from the input type.
Source§

impl From<TimeDelta> for FloatDuration

Available on crate feature chrono only.
Source§

fn from(from: Duration) -> FloatDuration

Converts to this type from the input type.
Source§

impl FromDuration<Duration> for FloatDuration

Source§

type Error = ()

Source§

fn from_duration(from: Duration) -> Result<FloatDuration, ()>

Convert from into a Self object.
Source§

impl FromDuration<FloatDuration> for Duration

Source§

impl FromDuration<FloatDuration> for Duration

Available on crate feature chrono only.
Source§

impl FromDuration<TimeDelta> for FloatDuration

Available on crate feature chrono only.
Source§

type Error = ()

Source§

fn from_duration(from: Duration) -> Result<FloatDuration, ()>

Convert from into a Self object.
Source§

impl Mul<FloatDuration> for f64

Source§

type Output = FloatDuration

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: FloatDuration) -> FloatDuration

Performs the * operation. Read more
Source§

impl Mul<f64> for FloatDuration

Source§

type Output = FloatDuration

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> FloatDuration

Performs the * operation. Read more
Source§

impl MulAssign<f64> for FloatDuration

Source§

fn mul_assign(&mut self, rhs: f64)

Performs the *= operation. Read more
Source§

impl Neg for FloatDuration

Source§

type Output = FloatDuration

The resulting type after applying the - operator.
Source§

fn neg(self) -> FloatDuration

Performs the unary - operation. Read more
Source§

impl PartialEq for FloatDuration

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for FloatDuration

Source§

fn partial_cmp(&self, other: &FloatDuration) -> 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for FloatDuration

Available on crate feature serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Sub for FloatDuration

Source§

type Output = FloatDuration

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: FloatDuration) -> FloatDuration

Performs the - operation. Read more
Source§

impl SubAssign for FloatDuration

Source§

fn sub_assign(&mut self, rhs: FloatDuration)

Performs the -= operation. Read more
Source§

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

Source§

fn sum<I>(iter: I) -> FloatDuration
where I: Iterator<Item = &'a FloatDuration>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Sum for FloatDuration

Source§

fn sum<I>(iter: I) -> FloatDuration
where I: Iterator<Item = FloatDuration>,

Takes an iterator and generates Self from the elements by “summing up” the items.
Source§

impl Copy for FloatDuration

Source§

impl StructuralPartialEq for FloatDuration

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> IntoDuration<U> for T
where U: FromDuration<T>,

Source§

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

Source§

fn into_duration(self) -> Result<U, <U as FromDuration<T>>::Error>

Convert self into a T object.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,