pub struct Instant(/* private fields */);
Expand description
Represents a timestamp on a monotonically nondecreasing clock relative to the start of the user program.
§Precision
This type has a precision of 1 microsecond, and uses pros_sys::micros
internally.
Implementations§
source§impl Instant
impl Instant
sourcepub fn now() -> Self
pub fn now() -> Self
Returns an instant corresponding to “now”.
§Examples
use pros::time::Instant;
let now = Instant::now();
sourcepub fn duration_since(&self, earlier: Instant) -> Duration
pub fn duration_since(&self, earlier: Instant) -> Duration
Returns the amount of time elapsed from another instant to this one, or zero duration if that instant is later than this one.
§Examples
use core::time::Duration;
use pros::{time::Instant, task::delay};
let now = Instant::now();
delay(Duration::new(1, 0));
let new_now = Instant::now();
println!("{:?}", new_now.duration_since(now));
println!("{:?}", now.duration_since(new_now)); // 0ns
sourcepub const fn checked_duration_since(&self, earlier: Instant) -> Option<Duration>
pub const fn checked_duration_since(&self, earlier: Instant) -> Option<Duration>
Returns the amount of time elapsed from another instant to this one, or None if that instant is later than this one.
§Examples
use core::time::Duration;
use pros::{time::Instant, task::delay};
let now = Instant::now();
delay(Duration::new(1, 0));
let new_now = Instant::now();
println!("{:?}", new_now.checked_duration_since(now));
println!("{:?}", now.checked_duration_since(new_now)); // None
sourcepub fn saturating_duration_since(&self, earlier: Instant) -> Duration
pub fn saturating_duration_since(&self, earlier: Instant) -> Duration
Returns the amount of time elapsed from another instant to this one, or zero duration if that instant is later than this one.
§Examples
use core::time::Duration;
use pros::{time::Instant, task::delay};
let instant = Instant::now();
let three_secs = Duration::from_secs(3);
delay(three_secs);
assert!(instant.elapsed() >= three_secs);
sourcepub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
Returns the amount of time elapsed since this instant.
§Examples
use core::time::Duration;
use pros::{time::Instant, task::delay};
let instant = Instant::now();
let three_secs = Duration::from_secs(3);
delay(three_secs);
assert!(instant.elapsed() >= three_secs);
sourcepub fn checked_add(self, rhs: Duration) -> Option<Instant>
pub fn checked_add(self, rhs: Duration) -> Option<Instant>
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.
sourcepub fn checked_sub(self, rhs: Duration) -> Option<Instant>
pub fn checked_sub(self, rhs: Duration) -> Option<Instant>
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.
Trait Implementations§
source§impl AddAssign<Duration> for Instant
impl AddAssign<Duration> for Instant
source§fn add_assign(&mut self, other: Duration)
fn add_assign(&mut self, other: Duration)
+=
operation. Read moresource§impl Ord for Instant
impl Ord for Instant
source§impl PartialEq for Instant
impl PartialEq for Instant
source§impl PartialOrd for Instant
impl PartialOrd for Instant
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl SubAssign<Duration> for Instant
impl SubAssign<Duration> for Instant
source§fn sub_assign(&mut self, other: Duration)
fn sub_assign(&mut self, other: Duration)
-=
operation. Read more