Struct Timer

Source
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,

Source

pub fn new(clock: &'a CLOCK) -> Self

Create a new Timer tied to a specific clock

Source

pub fn duration(&self) -> Result<Duration, TimerError>

Get the Duration of the current timer, or Err if it is not running

Source

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.

Source

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.

Source

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

Source

pub fn try_start(&mut self, duration: Duration) -> Result<(), TimerError>

Start the timer. Can fail due to overflow in the Instant type

Source

pub fn try_wait(&mut self) -> Result<(), TimerError>

Wait for the timer. Fails if the timer is not running.

Source

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.

Source

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.

Source

pub fn cancel(&mut self) -> Result<(), TimerError>

Cancel the timer. Return a NotRunning error if the timer is not running

Trait Implementations§

Source§

impl<'a, CLOCK> Debug for Timer<'a, CLOCK>
where CLOCK: Clock + Debug, CLOCK::Instant: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, CLOCK> Freeze for Timer<'a, CLOCK>
where <CLOCK as Clock>::Instant: Freeze,

§

impl<'a, CLOCK> RefUnwindSafe for Timer<'a, CLOCK>
where CLOCK: RefUnwindSafe,

§

impl<'a, CLOCK> Send for Timer<'a, CLOCK>
where CLOCK: Sync,

§

impl<'a, CLOCK> Sync for Timer<'a, CLOCK>
where CLOCK: Sync,

§

impl<'a, CLOCK> Unpin for Timer<'a, CLOCK>

§

impl<'a, CLOCK> UnwindSafe for Timer<'a, CLOCK>
where CLOCK: RefUnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.