pub trait InstantContext: Sized {
// Required methods
fn checked_add_wc(&self, duration: Duration) -> Result<Self>;
fn checked_sub_wc(&self, duration: Duration) -> Result<Self>;
fn checked_duration_since_wc(&self, earlier: Instant) -> Result<Duration>;
}Required Methods§
Sourcefn checked_add_wc(&self, duration: Duration) -> Result<Self>
fn checked_add_wc(&self, duration: Duration) -> Result<Self>
Returns Some(t) where t is the time self + duration if t can be represented as
Instant (which means it’s inside the bounds of the underlying data structure), None
otherwise.
Sourcefn checked_sub_wc(&self, duration: Duration) -> Result<Self>
fn checked_sub_wc(&self, duration: Duration) -> Result<Self>
Returns Some(t) where t is the time self - duration if t can be represented as
Instant (which means it’s inside the bounds of the underlying data structure), None
otherwise.
Sourcefn checked_duration_since_wc(&self, earlier: Instant) -> Result<Duration>
fn checked_duration_since_wc(&self, earlier: Instant) -> Result<Duration>
Returns the amount of time elapsed from another instant to this one, or None if that instant is later than this one.
Due to monotonicity bugs, even under correct logical ordering of the passed Instants,
this method can return None.
§Examples
use std::time::{Duration, Instant};
use std::thread::sleep;
let now = Instant::now();
sleep(Duration::new(1, 0));
let new_now = Instant::now();
println!("{:?}", new_now.checked_duration_since(now));
println!("{:?}", now.checked_duration_since(new_now)); // NoneDyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".