Struct game_time::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 signum(&self) -> f64
Return a number that represents the sign of self
.
- 1.0 if the value is positive,
+0.0
orINFINITY
- -1.0 if the value is negative,
-0.0
orNEG_INFINITY
NAN
if the value isNAN
fn max(self, other: FloatDuration) -> FloatDuration
Return the maximum of two durations.
fn min(self, other: FloatDuration) -> FloatDuration
Return the minimum of two durations.
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
.
Equivalent to using FloatDuration::from(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.
Equivalent to using FloatDuration::from(duration)
Trait Implementations
impl Neg for FloatDuration
[src]
type Output = FloatDuration
fn neg(self) -> FloatDuration
impl Debug for FloatDuration
[src]
fn fmt(&self, __arg_0: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter.
impl AddAssign<FloatDuration> for FloatDuration
[src]
fn add_assign(&mut self, rhs: FloatDuration)
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 FromDuration<Duration> for FloatDuration
[src]
type Error = ()
fn from_duration(from: Duration) -> Result<FloatDuration, ()>
impl FromDuration<Duration> for FloatDuration
[src]
type Error = ()
fn from_duration(from: Duration) -> Result<FloatDuration, ()>
impl Display for FloatDuration
[src]
impl PartialOrd<FloatDuration> for FloatDuration
[src]
fn partial_cmp(&self, __arg_0: &FloatDuration) -> Option<Ordering>
fn lt(&self, __arg_0: &FloatDuration) -> bool
fn le(&self, __arg_0: &FloatDuration) -> bool
fn gt(&self, __arg_0: &FloatDuration) -> bool
fn ge(&self, __arg_0: &FloatDuration) -> bool
impl Default for FloatDuration
[src]
fn default() -> FloatDuration
Returns the "default value" for a type. Read more
impl Sub<FloatDuration> for FloatDuration
[src]
type Output = FloatDuration
fn sub(self, rhs: FloatDuration) -> FloatDuration
impl Copy for FloatDuration
[src]
impl Add<FloatDuration> for FloatDuration
[src]
type Output = FloatDuration
fn add(self, rhs: FloatDuration) -> FloatDuration
impl From<Duration> for FloatDuration
[src]
fn from(from: Duration) -> FloatDuration
impl From<Duration> for FloatDuration
[src]
fn from(from: Duration) -> FloatDuration
impl Div<FloatDuration> for FloatDuration
[src]
type Output = f64
fn div(self, rhs: FloatDuration) -> f64
impl Div<f64> for FloatDuration
[src]
type Output = FloatDuration
fn div(self, rhs: f64) -> FloatDuration
impl Mul<f64> for FloatDuration
[src]
type Output = FloatDuration
fn mul(self, rhs: f64) -> FloatDuration
impl Serialize for FloatDuration
[src]
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
impl ApproxEq for FloatDuration
[src]
type Epsilon = f64
fn default_epsilon() -> f64
fn default_max_relative() -> f64
fn default_max_ulps() -> u32
fn relative_eq(
&self,
other: &FloatDuration,
epsilon: f64,
max_relative: f64
) -> bool
&self,
other: &FloatDuration,
epsilon: f64,
max_relative: f64
) -> bool
fn ulps_eq(&self, other: &FloatDuration, epsilon: f64, max_ulps: u32) -> bool
impl SubAssign<FloatDuration> for FloatDuration
[src]
fn sub_assign(&mut self, rhs: FloatDuration)
impl<'de> Deserialize<'de> for FloatDuration
[src]
fn deserialize<D>(
deserializer: D
) -> Result<FloatDuration, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
deserializer: D
) -> Result<FloatDuration, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
impl<'a> Sum<&'a FloatDuration> for FloatDuration
[src]
fn sum<I>(iter: I) -> FloatDuration where
I: Iterator<Item = &'a FloatDuration>,
I: Iterator<Item = &'a FloatDuration>,
impl Sum<FloatDuration> for FloatDuration
[src]
fn sum<I>(iter: I) -> FloatDuration where
I: Iterator<Item = FloatDuration>,
I: Iterator<Item = FloatDuration>,
impl DivAssign<f64> for FloatDuration
[src]
fn div_assign(&mut self, rhs: f64)
impl PartialEq<FloatDuration> 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 !=
.