Open
Description
I'd like to use a timer to measure how long something takes. I can't use the timer trait currently since there's no way to read the current timer value. What do we think about adding a method to CountDown
that returns the current timer value?
For example, see lap
method below.
pub trait CountDown {
/// The unit of time used by this timer
type Time;
/// Starts a new count down
fn start<T>(&mut self, count: T)
where
T: Into<Self::Time>;
/// Returns the current value of the timer as how much time has elapsed since starting.
fn lap<T>(&self,) -> T
where
T: Into<Self::Time>;
/// Non-blockingly "waits" until the count down finishes
///
/// # Contract
///
/// - If `Self: Periodic`, the timer will start a new count down right after the last one
/// finishes.
/// - Otherwise the behavior of calling `wait` after the last call returned `Ok` is UNSPECIFIED.
/// Implementers are suggested to panic on this scenario to signal a programmer error.
fn wait(&mut self) -> nb::Result<(), Infallible>;
}