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>
impl<const NOM: u32, const DENOM: u32> Instant<u64, NOM, DENOM>
Sourcepub const fn from_ticks(ticks: u64) -> Instant<u64, NOM, DENOM>
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);
Sourcepub const fn ticks(&self) -> u64
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);
Sourcepub const fn const_cmp(self, other: Instant<u64, NOM, DENOM>) -> Ordering
pub const fn const_cmp(self, other: Instant<u64, NOM, DENOM>) -> Ordering
Const comparison of Instant
s.
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);
Sourcepub const fn duration_since_epoch(self) -> Duration<u64, NOM, DENOM>
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);
Sourcepub const fn checked_duration_since(
self,
other: Instant<u64, NOM, DENOM>,
) -> Option<Duration<u64, NOM, DENOM>>
pub const fn checked_duration_since( self, other: Instant<u64, NOM, DENOM>, ) -> Option<Duration<u64, NOM, DENOM>>
Duration between Instant
s.
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);
Sourcepub 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>>
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);
Sourcepub 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>>
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>
impl<const NOM: u32, const DENOM: u32> Add<Duration<u32, NOM, DENOM>> for Instant<u64, NOM, DENOM>
Source§impl<const NOM: u32, const DENOM: u32> Add<Duration<u64, NOM, DENOM>> for Instant<u64, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> Add<Duration<u64, NOM, DENOM>> for Instant<u64, NOM, DENOM>
Source§impl<const NOM: u32, const DENOM: u32> AddAssign<Duration<u32, NOM, DENOM>> for Instant<u64, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> AddAssign<Duration<u32, NOM, DENOM>> for Instant<u64, NOM, DENOM>
Source§impl<const NOM: u32, const DENOM: u32> AddAssign<Duration<u64, NOM, DENOM>> for Instant<u64, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> AddAssign<Duration<u64, NOM, DENOM>> for Instant<u64, NOM, DENOM>
Source§impl<const NOM: u32, const DENOM: u32> Ord for Instant<u64, NOM, DENOM>
impl<const NOM: u32, const DENOM: u32> Ord for Instant<u64, NOM, DENOM>
Source§fn cmp(&self, other: &Instant<u64, NOM, DENOM>) -> Ordering
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) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<const NOM: u32, const DENOM: u32> PartialOrd for Instant<u64, NOM, DENOM>
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>
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.