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 vex_sdk::vexSystemHighResTimeGet
internally.
Implementations§
Source§impl Instant
impl Instant
Sourcepub fn now() -> Self
pub fn now() -> Self
Returns an instant corresponding to “now”.
§Examples
use vexide::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 vexide::time::Instant;
let now = Instant::now();
sleep(Duration::new(1, 0)).await;
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 vexide::time::Instant;
let now = Instant::now();
sleep(Duration::new(1, 0)).await;
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 vexide::time::Instant;
let now = Instant::now();
sleep(Duration::new(1, 0)).await;
let new_now = Instant::now();
println!("{:?}", new_now.saturating_duration_since(now));
println!("{:?}", now.saturating_duration_since(new_now)); // 0ns
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 vexide::time::Instant;
let instant = Instant::now();
let three_secs = Duration::from_secs(3);
sleep(three_secs).await;
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 Add<Duration> for Instant
impl Add<Duration> for Instant
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 PartialOrd for Instant
impl PartialOrd for Instant
Source§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