Struct Timer

Source
pub struct Timer<'a, Type, State, Clock: Clock, Dur: Duration> { /* private fields */ }
Expand description

A Timer counts toward an expiration, can be polled for elapsed and remaining time, and can be one-shot or continuous/periodic.

Implementations§

Source§

impl<'a, Clock: Clock, Dur: Duration> Timer<'_, None, None, Clock, Dur>

Source

pub fn new( clock: &Clock, duration: Dur, ) -> Timer<'_, OneShot, Armed, Clock, Dur>

Construct a new, OneShot Timer

Source§

impl<'a, Type, State, Clock: Clock, Dur: Duration> Timer<'a, Type, State, Clock, Dur>

Source

pub fn into_oneshot(self) -> Timer<'a, OneShot, State, Clock, Dur>

Change timer type to one-shot

Source

pub fn into_periodic(self) -> Timer<'a, Periodic, State, Clock, Dur>

Change timer type into periodic

Source§

impl<'a, Type, Clock: Clock, Dur: Duration> Timer<'a, Type, Armed, Clock, Dur>

Source

pub fn start(self) -> Result<Timer<'a, Type, Running, Clock, Dur>, TimeError>
where Clock::T: TryFrom<Dur::T>, Dur: FixedPoint,

Start the timer from this instant

Source§

impl<Type, Clock: Clock, Dur: Duration> Timer<'_, Type, Running, Clock, Dur>

Source

pub fn elapsed(&self) -> Result<Dur, TimeError>
where Dur: FixedPoint + TryFrom<Generic<Clock::T>, Error = ConversionError>, Dur::T: TryFrom<Clock::T>, Clock::T: TryFrom<Dur::T>,

Returns the Duration of time elapsed since it was started

The duration is truncated, not rounded.

The units of the Duration are the same as that used to construct the Timer.

Source

pub fn remaining(&self) -> Result<Dur, TimeError>
where Dur: FixedPoint + TryFrom<Generic<Clock::T>, Error = ConversionError>, Dur::T: TryFrom<u32> + TryFrom<Clock::T>, Clock::T: TryFrom<Dur::T>,

Returns the Duration until the expiration of the timer

The duration is truncated, not rounded.

The units of the Duration are the same as that used to construct the Timer.

Source§

impl<'a, Clock: Clock, Dur: Duration> Timer<'a, OneShot, Running, Clock, Dur>

Source

pub fn wait(self) -> Result<Timer<'a, OneShot, Armed, Clock, Dur>, TimeError>

Block until the timer has expired

Source

pub fn is_expired(&self) -> Result<bool, TimeError>

Check whether the timer has expired

The timer is not restarted

Source§

impl<Clock: Clock, Dur: Duration> Timer<'_, Periodic, Running, Clock, Dur>

Source

pub fn wait(self) -> Result<Self, TimeError>
where Instant<Clock>: Add<Dur, Output = Instant<Clock>>,

Block until the timer has expired

The timer is restarted

Source

pub fn period_complete(&mut self) -> Result<bool, TimeError>
where Instant<Clock>: Add<Dur, Output = Instant<Clock>>,

Check whether a periodic timer has elapsed

The timer is restarted if it has elapsed.

Trait Implementations§

Source§

impl<'a, Type: Debug, State: Debug, Clock: Debug + Clock, Dur: Debug + Duration> Debug for Timer<'a, Type, State, Clock, Dur>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a, Type: Hash, State: Hash, Clock: Hash + Clock, Dur: Hash + Duration> Hash for Timer<'a, Type, State, Clock, Dur>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more

Auto Trait Implementations§

§

impl<'a, Type, State, Clock, Dur> Freeze for Timer<'a, Type, State, Clock, Dur>
where Dur: Freeze, <Clock as Clock>::T: Freeze,

§

impl<'a, Type, State, Clock, Dur> RefUnwindSafe for Timer<'a, Type, State, Clock, Dur>
where Dur: RefUnwindSafe, Clock: RefUnwindSafe, <Clock as Clock>::T: RefUnwindSafe, Type: RefUnwindSafe, State: RefUnwindSafe,

§

impl<'a, Type, State, Clock, Dur> Send for Timer<'a, Type, State, Clock, Dur>
where Dur: Send, Clock: Sync, <Clock as Clock>::T: Send, Type: Send, State: Send,

§

impl<'a, Type, State, Clock, Dur> Sync for Timer<'a, Type, State, Clock, Dur>
where Dur: Sync, Clock: Sync, <Clock as Clock>::T: Sync, Type: Sync, State: Sync,

§

impl<'a, Type, State, Clock, Dur> Unpin for Timer<'a, Type, State, Clock, Dur>
where Dur: Unpin, <Clock as Clock>::T: Unpin, Type: Unpin, State: Unpin,

§

impl<'a, Type, State, Clock, Dur> UnwindSafe for Timer<'a, Type, State, Clock, Dur>
where Dur: UnwindSafe, Clock: RefUnwindSafe, <Clock as Clock>::T: UnwindSafe, Type: UnwindSafe, State: UnwindSafe,

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.