zephyr::time

Type Alias Instant

Source
pub type Instant = Instant<Tick, 1, SYS_FREQUENCY>;
Expand description

An Instant appropriate for Zephyr calls that expect a k_timeout_t. The result will be an absolute time in terms of system ticks.

Aliased Type§

struct Instant { /* private fields */ }

Implementations

Source§

impl<const NOM: u32, const DENOM: u32> Instant<u64, NOM, DENOM>

Source

pub const fn from_ticks(ticks: u64) -> Instant<u64, NOM, DENOM>

Create an Instant from a ticks value.

let _i = Instant::<u64, 1, 1_000>::from_ticks(1);
Source

pub const fn ticks(&self) -> u64

Extract the ticks from an Instant.

let i = Instant::<u64, 1, 1_000>::from_ticks(234);

assert_eq!(i.ticks(), 234);
Source

pub const fn const_cmp(self, other: Instant<u64, NOM, DENOM>) -> Ordering

Const comparison of Instants.

let i1 = Instant::<u64, 1, 1_000>::from_ticks(1);
let i2 = Instant::<u64, 1, 1_000>::from_ticks(2);

assert_eq!(i1.const_cmp(i2), core::cmp::Ordering::Less);

This function takes into account that ticks might wrap around. If the absolute values of self and other differ by more than half the possible range, it is assumed that an overflow occured and the result is reversed:

let i1 = Instant::<u64, 1, 1_000>::from_ticks(u64::MAX);
let i2 = Instant::<u64, 1, 1_000>::from_ticks(1);

assert_eq!(i1.const_cmp(i2), core::cmp::Ordering::Less);
Source

pub const fn duration_since_epoch(self) -> Duration<u64, NOM, DENOM>

Duration between since the start of the Instant. This assumes an instant which won’t wrap within the execution of the program.

let i = Instant::<u64, 1, 1_000>::from_ticks(11);

assert_eq!(i.duration_since_epoch().ticks(), 11);
Source

pub const fn checked_duration_since( self, other: Instant<u64, NOM, DENOM>, ) -> Option<Duration<u64, NOM, DENOM>>

Duration between Instants.

let i1 = Instant::<u64, 1, 1_000>::from_ticks(1);
let i2 = Instant::<u64, 1, 1_000>::from_ticks(2);

assert_eq!(i1.checked_duration_since(i2), None);
assert_eq!(i2.checked_duration_since(i1).unwrap().ticks(), 1);
Source

pub const fn checked_sub_duration<const O_NOM: u32, const O_DENOM: u32>( self, other: Duration<u64, O_NOM, O_DENOM>, ) -> Option<Instant<u64, NOM, DENOM>>

Subtract a Duration from an Instant while checking for overflow.

let i = Instant::<u64, 1, 1_000>::from_ticks(1);
let d = Duration::<u64, 1, 1_000>::from_ticks(1);

assert_eq!(i.checked_sub_duration(d).unwrap().ticks(), 0);
Source

pub const fn checked_add_duration<const O_NOM: u32, const O_DENOM: u32>( self, other: Duration<u64, O_NOM, O_DENOM>, ) -> Option<Instant<u64, NOM, DENOM>>

Add a Duration to an Instant while checking for overflow.

let i = Instant::<u64, 1, 1_000>::from_ticks(1);
let d = Duration::<u64, 1, 1_000>::from_ticks(1);

assert_eq!(i.checked_add_duration(d).unwrap().ticks(), 2);

Trait Implementations

Source§

impl<const NOM: u32, const DENOM: u32> Add<Duration<u32, NOM, DENOM>> for Instant<u64, NOM, DENOM>

Source§

type Output = Instant<u64, NOM, DENOM>

The resulting type after applying the + operator.
Source§

fn add( self, other: Duration<u32, NOM, DENOM>, ) -> <Instant<u64, NOM, DENOM> as Add<Duration<u32, NOM, DENOM>>>::Output

Performs the + operation. Read more
Source§

impl<const NOM: u32, const DENOM: u32> Add<Duration<u64, NOM, DENOM>> for Instant<u64, NOM, DENOM>

Source§

type Output = Instant<u64, NOM, DENOM>

The resulting type after applying the + operator.
Source§

fn add( self, other: Duration<u64, NOM, DENOM>, ) -> <Instant<u64, NOM, DENOM> as Add<Duration<u64, NOM, DENOM>>>::Output

Performs the + operation. Read more
Source§

impl<const NOM: u32, const DENOM: u32> AddAssign<Duration<u32, NOM, DENOM>> for Instant<u64, NOM, DENOM>

Source§

fn add_assign(&mut self, other: Duration<u32, NOM, DENOM>)

Performs the += operation. Read more
Source§

impl<const NOM: u32, const DENOM: u32> AddAssign<Duration<u64, NOM, DENOM>> for Instant<u64, NOM, DENOM>

Source§

fn add_assign(&mut self, other: Duration<u64, NOM, DENOM>)

Performs the += operation. Read more
Source§

impl<T, const NOM: u32, const DENOM: u32> Clone for Instant<T, NOM, DENOM>
where T: Clone,

Source§

fn clone(&self) -> Instant<T, NOM, DENOM>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T, const NOM: u32, const DENOM: u32> Debug for Instant<T, NOM, DENOM>
where T: Debug,

Source§

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

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

impl<const NOM: u32, const DENOM: u32> Display for Instant<u64, NOM, DENOM>

Source§

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

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

impl<const NOM: u32, const DENOM: u32> Ord for Instant<u64, NOM, DENOM>

Source§

fn cmp(&self, other: &Instant<u64, NOM, DENOM>) -> Ordering

This implementation deviates from the definition of Ord::cmp:

It takes into account that ticks might wrap around. If the absolute values of self and other differ by more than half the possible range, it is assumed that an overflow occured and the result is reversed.

That breaks the transitivity invariant: a < b and b < c no longer implies a < c.

1.21.0 · Source§

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

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

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

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

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

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

impl<const NOM: u32, const DENOM: u32> PartialEq for Instant<u64, NOM, DENOM>

Source§

fn eq(&self, other: &Instant<u64, NOM, DENOM>) -> bool

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

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<const NOM: u32, const DENOM: u32> PartialOrd for Instant<u64, NOM, DENOM>

Source§

fn partial_cmp(&self, other: &Instant<u64, NOM, DENOM>) -> Option<Ordering>

This implementation deviates from the definition of PartialOrd::partial_cmp:

It takes into account that ticks might wrap around. If the absolute values of self and other differ by more than half the possible range, it is assumed that an overflow occured and the result is reversed.

That breaks the transitivity invariant: a < b and b < c no longer implies a < c.

1.0.0 · Source§

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

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

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 · Source§

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

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

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<const NOM: u32, const DENOM: u32> Sub<Duration<u32, NOM, DENOM>> for Instant<u64, NOM, DENOM>

Source§

type Output = Instant<u64, NOM, DENOM>

The resulting type after applying the - operator.
Source§

fn sub( self, other: Duration<u32, NOM, DENOM>, ) -> <Instant<u64, NOM, DENOM> as Sub<Duration<u32, NOM, DENOM>>>::Output

Performs the - operation. Read more
Source§

impl<const NOM: u32, const DENOM: u32> Sub<Duration<u64, NOM, DENOM>> for Instant<u64, NOM, DENOM>

Source§

type Output = Instant<u64, NOM, DENOM>

The resulting type after applying the - operator.
Source§

fn sub( self, other: Duration<u64, NOM, DENOM>, ) -> <Instant<u64, NOM, DENOM> as Sub<Duration<u64, NOM, DENOM>>>::Output

Performs the - operation. Read more
Source§

impl<const NOM: u32, const DENOM: u32> Sub for Instant<u64, NOM, DENOM>

Source§

type Output = Duration<u64, NOM, DENOM>

The resulting type after applying the - operator.
Source§

fn sub( self, other: Instant<u64, NOM, DENOM>, ) -> <Instant<u64, NOM, DENOM> as Sub>::Output

Performs the - operation. Read more
Source§

impl<const NOM: u32, const DENOM: u32> SubAssign<Duration<u32, NOM, DENOM>> for Instant<u64, NOM, DENOM>

Source§

fn sub_assign(&mut self, other: Duration<u32, NOM, DENOM>)

Performs the -= operation. Read more
Source§

impl<const NOM: u32, const DENOM: u32> SubAssign<Duration<u64, NOM, DENOM>> for Instant<u64, NOM, DENOM>

Source§

fn sub_assign(&mut self, other: Duration<u64, NOM, DENOM>)

Performs the -= operation. Read more
Source§

impl<T, const NOM: u32, const DENOM: u32> Copy for Instant<T, NOM, DENOM>
where T: Copy,

Source§

impl<const NOM: u32, const DENOM: u32> Eq for Instant<u64, NOM, DENOM>