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::core::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::core::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)); // 0nssourcepub 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::core::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)); // Nonesourcepub 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::core::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)); // 0nssourcepub 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::core::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 moreimpl Copy for Instant
impl Eq for Instant
impl StructuralPartialEq for Instant
Auto Trait Implementations§
impl Freeze for Instant
impl RefUnwindSafe for Instant
impl Send for Instant
impl Sync for Instant
impl Unpin for Instant
impl UnwindSafe for Instant
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)