pub struct Timestamp {
pub nanoseconds: u128,
}Expand description
A Timestamp represents a point in time as nanoseconds since the UNIX epoch.
Fields§
§nanoseconds: u128Implementations§
Source§impl Timestamp
impl Timestamp
Sourcepub fn now() -> Self
pub fn now() -> Self
Returns the current time as a Timestamp.
§Examples
use transforms::time::Timestamp;
let now = Timestamp::now();Sourcepub fn zero() -> Self
pub fn zero() -> Self
Returns a Timestamp representing the UNIX epoch (0 nanoseconds).
This functionality is especially useful for static transforms.
§Examples
use transforms::time::Timestamp;
let zero = Timestamp::zero();
assert_eq!(zero.nanoseconds, 0);Sourcepub fn as_seconds(&self) -> Result<f64, TimestampError>
pub fn as_seconds(&self) -> Result<f64, TimestampError>
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 {
nanoseconds: 1_000_000_000,
};
let result = timestamp.as_seconds();
assert!(result.is_ok());
assert_eq!(result.unwrap(), 1.0);
let timestamp = Timestamp {
nanoseconds: 1_000_000_000_000_000_001,
};
let result = timestamp.as_seconds();
assert!(result.is_err());§Errors
Returns TimestampError::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 {
nanoseconds: 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
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 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.