pub struct LowResolutionTime { /* private fields */ }Expand description
Implementations§
Source§impl LowResolutionTime
impl LowResolutionTime
Sourcepub const EPOCH: LowResolutionTime
pub const EPOCH: LowResolutionTime
An anchor in time which represents the start of the clock.
In practice, the epoch represents the start of the Brain’s user processor, meaning the start of the current user program.
Sourcepub fn now() -> Self
pub fn now() -> Self
Returns a low-resolution timestamp corresponding to “now”.
§Examples
use vexide::time::LowResolutionTime;
let now = LowResolutionTime::now();Sourcepub const fn from_millis_since_epoch(millis: u32) -> Self
pub const fn from_millis_since_epoch(millis: u32) -> Self
Creates a new timestamp at the provided number of milliseconds since
LowResolutionTime::EPOCH.
§Use this sparingly.
This method generally only exists for compatibility with FFI and system APIs. The only clock
measurement that should be provided to millis should be measurements derived from the CPU1
private timer (e.g. vexSystemTimeGet) to ensure that clock drift is not a factor.
When possible, prefer using LowResolutionTime::now.
§Examples
use vexide::time::LowResolutionTime;
// Equivalent to `LowResolutionTime::now()`.
let now = LowResolutionTime::from_millis_since_epoch(unsafe { vex_sdk::vexSystemTimeGet() });Sourcepub fn duration_since(&self, earlier: LowResolutionTime) -> Duration
pub fn duration_since(&self, earlier: LowResolutionTime) -> Duration
Returns the amount of time elapsed from another timestamp to this one, or zero duration if that timestamp is later than this one.
§Examples
use std::time::Duration;
use vexide::{prelude::*, time::LowResolutionTime};
#[vexide::main]
async fn main(_peripherals: Peripherals) {
let now = LowResolutionTime::now();
sleep(Duration::new(1, 0)).await;
let new_now = LowResolutionTime::now();
println!("{:?}", new_now.duration_since(now));
println!("{:?}", now.duration_since(new_now)); // 0ns
}Sourcepub const fn checked_duration_since(
&self,
earlier: LowResolutionTime,
) -> Option<Duration>
pub const fn checked_duration_since( &self, earlier: LowResolutionTime, ) -> Option<Duration>
Returns the amount of time elapsed from another timestamp to this one, or None if that timestamp is later than this one.
§Examples
use std::time::Duration;
use vexide::{prelude::*, time::LowResolutionTime};
#[vexide::main]
async fn main(_peripherals: Peripherals) {
let now = LowResolutionTime::now();
sleep(Duration::new(1, 0)).await;
let new_now = LowResolutionTime::now();
println!("{:?}", new_now.checked_duration_since(now));
println!("{:?}", now.checked_duration_since(new_now)); // None
}Sourcepub fn saturating_duration_since(&self, earlier: LowResolutionTime) -> Duration
pub fn saturating_duration_since(&self, earlier: LowResolutionTime) -> Duration
Returns the amount of time elapsed from another timestamp to this one, or zero duration if that timestamp is later than this one.
§Examples
use std::time::Duration;
use vexide::{prelude::*, time::LowResolutionTime};
#[vexide::main]
async fn main(_peripherals: Peripherals) {
let now = LowResolutionTime::now();
sleep(Duration::new(1, 0)).await;
let new_now = LowResolutionTime::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 timestamp.
§Examples
use std::time::Duration;
use vexide::{prelude::*, time::LowResolutionTime};
#[vexide::main]
async fn main(_peripherals: Peripherals) {
let start = LowResolutionTime::now();
let three_secs = Duration::from_secs(3);
sleep(three_secs).await;
assert!(start.elapsed() >= three_secs);
}Sourcepub fn checked_add(self, rhs: Duration) -> Option<LowResolutionTime>
pub fn checked_add(self, rhs: Duration) -> Option<LowResolutionTime>
Returns Some(t) where t is the time self + duration if t can be represented as
LowResolutionTime (which means it’s inside the bounds of the underlying data structure),
None otherwise.
Sourcepub fn checked_sub(self, rhs: Duration) -> Option<LowResolutionTime>
pub fn checked_sub(self, rhs: Duration) -> Option<LowResolutionTime>
Returns Some(t) where t is the time self - duration if t can be represented as
LowResolutionTime (which means it’s inside the bounds of the underlying data structure),
None otherwise.
Trait Implementations§
Source§impl Add<Duration> for LowResolutionTime
impl Add<Duration> for LowResolutionTime
Source§fn add(self, rhs: Duration) -> Self::Output
fn add(self, rhs: Duration) -> Self::Output
§Panics
This function may panic if the resulting point in time cannot be represented by the
underlying data structure. See LowResolutionTime::checked_add for a version without
panic.
Source§type Output = LowResolutionTime
type Output = LowResolutionTime
+ operator.Source§impl AddAssign<Duration> for LowResolutionTime
impl AddAssign<Duration> for LowResolutionTime
Source§fn add_assign(&mut self, other: Duration)
fn add_assign(&mut self, other: Duration)
+= operation. Read moreSource§impl Clone for LowResolutionTime
impl Clone for LowResolutionTime
Source§fn clone(&self) -> LowResolutionTime
fn clone(&self) -> LowResolutionTime
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for LowResolutionTime
impl Debug for LowResolutionTime
Source§impl Hash for LowResolutionTime
impl Hash for LowResolutionTime
Source§impl Ord for LowResolutionTime
impl Ord for LowResolutionTime
Source§impl PartialEq for LowResolutionTime
impl PartialEq for LowResolutionTime
Source§impl PartialOrd for LowResolutionTime
impl PartialOrd for LowResolutionTime
Source§fn partial_cmp(&self, other: &LowResolutionTime) -> Option<Ordering>
fn partial_cmp(&self, other: &LowResolutionTime) -> Option<Ordering>
Source§impl Sub<Duration> for LowResolutionTime
impl Sub<Duration> for LowResolutionTime
Source§type Output = LowResolutionTime
type Output = LowResolutionTime
- operator.Source§fn sub(self, other: Duration) -> LowResolutionTime
fn sub(self, other: Duration) -> LowResolutionTime
- operation. Read moreSource§impl Sub for LowResolutionTime
impl Sub for LowResolutionTime
Source§impl SubAssign<Duration> for LowResolutionTime
impl SubAssign<Duration> for LowResolutionTime
Source§fn sub_assign(&mut self, other: Duration)
fn sub_assign(&mut self, other: Duration)
-= operation. Read moreimpl Copy for LowResolutionTime
impl Eq for LowResolutionTime
impl StructuralPartialEq for LowResolutionTime
Auto Trait Implementations§
impl Freeze for LowResolutionTime
impl RefUnwindSafe for LowResolutionTime
impl Send for LowResolutionTime
impl Sync for LowResolutionTime
impl Unpin for LowResolutionTime
impl UnwindSafe for LowResolutionTime
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)