pub trait Instant:
Copy
+ Debug
+ Sized {
// Required methods
fn now() -> Self;
fn checked_add(&self, duration: Duration) -> Option<Self>;
fn checked_sub(&self, duration: Duration) -> Option<Self>;
fn saturating_duration_since(&self, earlier: Self) -> Duration;
}Expand description
A trait outlining the behavior of a timekeeping type.
This trait allows libsw to be agnostic about timekeeping: any type which
implements Instant can be used within a
Stopwatch.
§Provided implementations
libsw_core provides Instant implementations for timekeeping types in the
standard library.
| Type | Feature flag | Notes |
|---|---|---|
std::time::Instant | std | |
std::time::SystemTime | std | |
tokio::time::Instant | tokio | |
coarsetime::Instant | coarsetime | |
quanta::Instant | quanta | |
time::Instant | time | Deprecated. |
If a timekeeping type you want to use isn’t supported out of the box, please
consider filing an issue
on GitHub. If you already implemented Instant for it, consider sending a
PR upstream.
Required Methods§
Sourcefn checked_add(&self, duration: Duration) -> Option<Self>
fn checked_add(&self, duration: Duration) -> Option<Self>
Sourcefn checked_sub(&self, duration: Duration) -> Option<Self>
fn checked_sub(&self, duration: Duration) -> Option<Self>
Sourcefn saturating_duration_since(&self, earlier: Self) -> Duration
fn saturating_duration_since(&self, earlier: Self) -> Duration
Returns the Duration that has elapsed since earlier, returning
Duration::ZERO if earlier is ahead of self.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Instant for SystemTime
Available on crate feature std only.
impl Instant for SystemTime
Available on crate feature
std only.