pub struct Duration<R: Rate>(/* private fields */);Expand description
A span of ticks at rate R.
The count wraps after 2^32 ticks, which is twelve days at 4096 Hz and months
below that. Nothing here allows for that: a span measured across the wrap
comes back wrong rather than saturated, so a machine left running that long
after Timer::start reads the wrong time.
Implementations§
Source§impl<R: Rate> Duration<R>
impl<R: Rate> Duration<R>
Sourcepub const fn from_ticks(ticks: u32) -> Self
pub const fn from_ticks(ticks: u32) -> Self
A span of ticks.
Sourcepub const fn from_ms(ms: u32) -> Self
pub const fn from_ms(ms: u32) -> Self
The shortest span of at least ms milliseconds.
Rounded up to a whole tick, so comparing against this is the answer to
“has ms passed”. At 16 Hz a tick is 63 ms, and nothing shorter can be
told apart.
Sourcepub fn ms(self) -> u32
pub fn ms(self) -> u32
The span in milliseconds, rounded down.
Do not compare against this. It multiplies, and that is not cheap enough
to run each time a program asks whether a span has passed.
from_ms converts at compile time instead, leaving a
plain comparison on ticks:
if elapsed >= Duration::from_ms(5000) { .. } // one comparison
if elapsed.ms() >= 5000 { .. } // a multiply firstThis is for a number to show or to log.