pub struct Timer<'a, CLOCK>where
CLOCK: Clock,{ /* private fields */ }
Expand description
An instance of a timer tied to a specific Clock and Timing Duration type.
Implementations§
Source§impl<'a, CLOCK> Timer<'a, CLOCK>where
CLOCK: Clock,
impl<'a, CLOCK> Timer<'a, CLOCK>where
CLOCK: Clock,
Sourcepub fn duration(&self) -> Result<Duration, TimerError>
pub fn duration(&self) -> Result<Duration, TimerError>
Get the Duration of the current timer, or Err if it is not running
Sourcepub fn is_running(&self) -> Result<bool, TimerError>
pub fn is_running(&self) -> Result<bool, TimerError>
If the timer is running, this is true. If not, it is false. It can also return an error from the Clock.
Sourcepub fn is_expired(&self) -> Result<bool, TimerError>
pub fn is_expired(&self) -> Result<bool, TimerError>
If the timer is expired, this is true. If not, it is false. It can also return an error from the Clock.
Sourcepub fn duration_left(&self) -> Result<Duration, TimerError>
pub fn duration_left(&self) -> Result<Duration, TimerError>
Get the Duration until expire of the current timer, or Err if it is not running or if “now” could not be calculated
Sourcepub fn try_start(&mut self, duration: Duration) -> Result<(), TimerError>
pub fn try_start(&mut self, duration: Duration) -> Result<(), TimerError>
Start the timer. Can fail due to overflow in the Instant type
Sourcepub fn try_wait(&mut self) -> Result<(), TimerError>
pub fn try_wait(&mut self) -> Result<(), TimerError>
Wait for the timer. Fails if the timer is not running.
Sourcepub fn start(&mut self, duration: Duration)
pub fn start(&mut self, duration: Duration)
Start the timer. Can fail due to overflow in the Instant type
Note: Panics on failure, use try_start if you want to handle errors.
Sourcepub fn wait(&mut self) -> Result<(), Void>
pub fn wait(&mut self) -> Result<(), Void>
Wait for the timer. Fails if the timer is not running
Note: Panics on failure or if the timer is not running, use try_wait if you want to handle errors.
Sourcepub fn cancel(&mut self) -> Result<(), TimerError>
pub fn cancel(&mut self) -> Result<(), TimerError>
Cancel the timer. Return a NotRunning error if the timer is not running