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() -> Timestamp
pub fn zero() -> Timestamp
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() -> Timestamp
fn static_timestamp() -> Timestamp
Returns the static timestamp value. Read more
Source§fn duration_since(self, earlier: Timestamp) -> Result<Duration, TimeError>
fn duration_since(self, earlier: Timestamp) -> Result<Duration, TimeError>
Returns elapsed time between two timestamps. Read more
Source§fn checked_add(self, rhs: Duration) -> Result<Timestamp, TimeError>
fn checked_add(self, rhs: Duration) -> Result<Timestamp, TimeError>
Adds duration to timestamp using checked arithmetic. Read more
Source§fn checked_sub(self, rhs: Duration) -> Result<Timestamp, TimeError>
fn checked_sub(self, rhs: Duration) -> Result<Timestamp, 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.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.