pub struct Timestamp {
pub t: u128,
}Expand description
Default concrete time type used by this crate.
Timestamp stores a time value in u128 nanoseconds.
For custom clocks, implement crate::time::TimePoint on your own type and
use it with Registry<T>.
Fields§
§t: u128Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub fn zero() -> Self
pub fn zero() -> Self
Returns a Timestamp initialized at zero.
This functionality is especially useful for static transforms.
§Examples
use transforms::time::Timestamp;
let zero = Timestamp::zero();
assert_eq!(zero.t, 0);Sourcepub fn as_seconds(&self) -> Result<f64, TimeError>
pub fn as_seconds(&self) -> Result<f64, TimeError>
Converts the Timestamp to seconds as a floating-point number.
Returns an error if the conversion results in accuracy loss.
§Examples
use transforms::time::Timestamp;
let timestamp = Timestamp { t: 1_000_000_000 };
let result = timestamp.as_seconds();
assert!(result.is_ok());
assert_eq!(result.unwrap(), 1.0);
let timestamp = Timestamp {
t: 1_000_000_000_000_000_001,
};
let result = timestamp.as_seconds();
assert!(result.is_err());§Errors
Returns TimeError::AccuracyLoss if the conversion is not exact.
Sourcepub fn as_seconds_unchecked(&self) -> f64
pub fn as_seconds_unchecked(&self) -> f64
Converts the Timestamp to seconds as a floating-point number without checking for accuracy.
§Examples
use transforms::time::Timestamp;
let timestamp = Timestamp {
t: 1_000_000_000_000_000_001,
};
let seconds = timestamp.as_seconds_unchecked();
assert_eq!(seconds, 1_000_000_000.0);Trait Implementations§
Source§impl Ord for Timestamp
impl Ord for Timestamp
Source§impl PartialOrd for Timestamp
impl PartialOrd for Timestamp
Source§impl TimePoint for Timestamp
impl TimePoint for Timestamp
Source§fn static_timestamp() -> Self
fn static_timestamp() -> Self
Returns the static timestamp value. Read more
Source§fn duration_since(self, earlier: Self) -> Result<Duration, TimeError>
fn duration_since(self, earlier: Self) -> Result<Duration, TimeError>
Returns elapsed time between two timestamps. Read more
Source§fn checked_add(self, rhs: Duration) -> Result<Self, TimeError>
fn checked_add(self, rhs: Duration) -> Result<Self, TimeError>
Adds duration to timestamp using checked arithmetic. Read more
Source§fn checked_sub(self, rhs: Duration) -> Result<Self, TimeError>
fn checked_sub(self, rhs: Duration) -> Result<Self, TimeError>
Subtracts duration from timestamp using checked arithmetic. Read more
impl Copy for Timestamp
impl Eq for Timestamp
impl StructuralPartialEq for Timestamp
Auto Trait Implementations§
impl Freeze for Timestamp
impl RefUnwindSafe for Timestamp
impl Send for Timestamp
impl Sync for Timestamp
impl Unpin for Timestamp
impl UnsafeUnpin for Timestamp
impl UnwindSafe for Timestamp
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.