#[repr(C, u8)]pub enum Instant {
System(InstantPtr),
Tick(SystemTick),
}Expand description
A point in time, either from the system clock or a tick counter.
Use Instant::System on platforms with std, Instant::Tick on embedded/no_std.
Variants§
System(InstantPtr)
System time from std::time::Instant (requires “std” feature)
Tick(SystemTick)
Tick-based time for embedded systems without a real-time clock
Implementations§
Source§impl Instant
impl Instant
Sourcepub fn now() -> Self
pub fn now() -> Self
Returns the current system time.
On systems with std, this uses std::time::Instant::now().
On no_std systems, this returns a zero tick.
Sourcepub fn linear_interpolate(&self, start: Self, end: Self) -> f32
pub fn linear_interpolate(&self, start: Self, end: Self) -> f32
Returns a number from 0.0 to 1.0 indicating the current linear interpolation value between (start, end)
Sourcepub fn add_optional_duration(&self, duration: Option<&Duration>) -> Self
pub fn add_optional_duration(&self, duration: Option<&Duration>) -> Self
Adds a duration to the instant.
The duration’s UNIT need not match the instant’s: a Tick duration added
to a System instant is converted at TICKS_PER_SECOND, and a System
duration added to a Tick instant is converted to whole ticks.
§Why the mismatch is converted rather than dropped
This used to return self unchanged for a unit mismatch, which turned a
Duration::Tick interval on a wall-clock timer into a schedule point of
last_run + 0 — Timer::instant_of_next_run is literally
last_run + delay + interval, so the timer reported itself permanently
overdue and LayoutWindow::time_until_next_timer_ms answered Some(0)
for it, i.e. “block for zero milliseconds” to any loop that consults it.
System + System still overflow-panics on an absurd duration (that is
StdInstant’s own behaviour, characterised in the tests); the tick arms
saturate.
Sourcepub fn into_std_instant(self) -> StdInstant
pub fn into_std_instant(self) -> StdInstant
Converts to std::time::Instant (panics if Tick variant).
Sourcepub fn duration_since(&self, earlier: &Self) -> Duration
pub fn duration_since(&self, earlier: &Self) -> Duration
Calculates the duration since an earlier point in time.
Saturates to a zero duration in the degenerate cases (earlier is actually
later than self, or the two instants are of mismatched kinds) instead
of panicking — this runs on the hot event-loop path and must not crash.
Trait Implementations§
impl Eq for Instant
Source§impl From<Instant> for Instant
Available on crate feature std only.
impl From<Instant> for Instant
std only.