libsw_core

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 flag
std::time::Instantstd
std::time::SystemTimestd

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§