Struct crystalorb::timestamp::FloatTimestamp [−][src]
pub struct FloatTimestamp(_);
Expand description
Representation of time in the same units as Timestamp
, but whereas Timestamp
identifies
which whole number of frames only, FloatTimestamp
can represent any time in the continuous
region between two adjacent frames.
Implementations
Find the corresponding time in seconds for this float timestamp. Since timestamps repeat over time, this function returns the time closest to zero. This makes it useful to find the number of seconds between two float timestamps.
Example
use crystalorb::timestamp::FloatTimestamp;
use float_cmp::approx_eq;
const TIMESTEP: f64 = 1.0 / 60.0;
// Given two float timestamps.
let t1 = FloatTimestamp::from_unwrapped(123.2);
let t2 = FloatTimestamp::from_unwrapped(123.7);
// We can get the seconds between these two float timestamps.
let seconds_difference = (t2 - t1).as_seconds(TIMESTEP);
assert!(approx_eq!(f64, seconds_difference, 0.5 / 60.0, ulps=1));
Round up to the next whole-number Timestamp
(or its own value if it is already a
whole number).
Example
use crystalorb::timestamp::{FloatTimestamp, Timestamp};
let t1 = FloatTimestamp::from_unwrapped(123.4);
let t2 = FloatTimestamp::from_unwrapped(123.0);
assert_eq!(t1.ceil(), Timestamp::default() + 124);
assert_eq!(t2.ceil(), Timestamp::default() + 123);
Round down to the previous whole-number Timestamp
(or its own value if it is
already a whole number).
Example
use crystalorb::timestamp::{FloatTimestamp, Timestamp};
let t1 = FloatTimestamp::from_unwrapped(123.4);
let t2 = FloatTimestamp::from_unwrapped(123.0);
assert_eq!(t1.floor(), Timestamp::default() + 123);
assert_eq!(t2.floor(), Timestamp::default() + 123);
Trait Implementations
Returns the “default value” for a type. Read more
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>,
Deserialize this value from the given Serde deserializer. Read more
Performs the conversion.
Performs the conversion.
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
This method tests for !=
.
Auto Trait Implementations
impl RefUnwindSafe for FloatTimestamp
impl Send for FloatTimestamp
impl Sync for FloatTimestamp
impl Unpin for FloatTimestamp
impl UnwindSafe for FloatTimestamp
Blanket Implementations
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more