LowResolutionTime

Struct LowResolutionTime 

Source
pub struct LowResolutionTime { /* private fields */ }
Expand description

A timestamp recorded by the Brain’s low-resolution private timer.

This type is not in sync with Instant, which instead uses the brain’s global high-resolution timer.

§Precision

This type has a precision of 1 millisecond.

Implementations§

Source§

impl LowResolutionTime

Source

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.

Source

pub fn now() -> Self

Returns a low-resolution timestamp corresponding to “now”.

§Examples
use vexide::time::LowResolutionTime;

let now = LowResolutionTime::now();
Source

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() });
Source

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
}
Source

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
}
Source

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
}
Source

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);
}
Source

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.

Source

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

Source§

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

The resulting type after applying the + operator.
Source§

impl AddAssign<Duration> for LowResolutionTime

Source§

fn add_assign(&mut self, other: Duration)

Performs the += operation. Read more
Source§

impl Clone for LowResolutionTime

Source§

fn clone(&self) -> LowResolutionTime

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LowResolutionTime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for LowResolutionTime

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given [Hasher]. Read more
1.3.0§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given [Hasher]. Read more
Source§

impl Ord for LowResolutionTime

Source§

fn cmp(&self, other: &LowResolutionTime) -> Ordering

This method returns an [Ordering] between self and other. Read more
1.21.0§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for LowResolutionTime

Source§

fn eq(&self, other: &LowResolutionTime) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for LowResolutionTime

Source§

fn partial_cmp(&self, other: &LowResolutionTime) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Sub<Duration> for LowResolutionTime

Source§

type Output = LowResolutionTime

The resulting type after applying the - operator.
Source§

fn sub(self, other: Duration) -> LowResolutionTime

Performs the - operation. Read more
Source§

impl Sub for LowResolutionTime

Source§

fn sub(self, other: LowResolutionTime) -> Duration

Returns the amount of time elapsed from another time to this one, or zero duration if that time is later than this one.

Source§

type Output = Duration

The resulting type after applying the - operator.
Source§

impl SubAssign<Duration> for LowResolutionTime

Source§

fn sub_assign(&mut self, other: Duration)

Performs the -= operation. Read more
Source§

impl Copy for LowResolutionTime

Source§

impl Eq for LowResolutionTime

Source§

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 T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.