Trait Instant

Source
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.

TypeFeature flagNotes
std::time::Instantstd
std::time::SystemTimestd
tokio::time::Instanttokio
coarsetime::Instantcoarsetime
quanta::Instantquanta
time::InstanttimeDeprecated.

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§

Source

fn now() -> Self

Returns the current instant in time.

Source

fn checked_add(&self, duration: Duration) -> Option<Self>

Returns an instant ahead of self by the given Duration of time.

Returns None if overflow occured, meaning the new instant was not representable with the underlying type.

Source

fn checked_sub(&self, duration: Duration) -> Option<Self>

Returns an instant previous to self by the given Duration of time.

Returns None if overflow occured, meaning the new instant was not representable with the underlying type.

Source

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 Instant

Available on crate feature std only.
Source§

fn now() -> Self

Source§

fn checked_add(&self, duration: Duration) -> Option<Self>

Source§

fn checked_sub(&self, duration: Duration) -> Option<Self>

Source§

fn saturating_duration_since(&self, earlier: Self) -> Duration

Source§

impl Instant for SystemTime

Available on crate feature std only.
Source§

fn now() -> Self

Source§

fn checked_add(&self, duration: Duration) -> Option<Self>

Source§

fn checked_sub(&self, duration: Duration) -> Option<Self>

Source§

fn saturating_duration_since(&self, earlier: Self) -> Duration

Source§

impl Instant for Instant

Available on crate feature coarsetime only.
Source§

fn now() -> Self

Source§

fn checked_add(&self, duration: Duration) -> Option<Self>

Source§

fn checked_sub(&self, duration: Duration) -> Option<Self>

Source§

fn saturating_duration_since(&self, earlier: Self) -> Duration

Source§

impl Instant for Instant

Available on crate feature quanta only.
Source§

fn now() -> Self

Source§

fn checked_add(&self, duration: Duration) -> Option<Self>

Source§

fn checked_sub(&self, duration: Duration) -> Option<Self>

Source§

fn saturating_duration_since(&self, earlier: Self) -> Duration

Source§

impl Instant for Instant

Available on crate feature tokio only.
Source§

fn now() -> Self

Source§

fn checked_add(&self, duration: Duration) -> Option<Self>

Source§

fn checked_sub(&self, duration: Duration) -> Option<Self>

Source§

fn saturating_duration_since(&self, earlier: Self) -> Duration

Implementors§