Struct embedded_timers::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>

Try to start the timer. Can fail due to errors from the clock.

source

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

Try to wait for the timer, return an error if it is not running.

Trait Implementations§

source§

impl<'a, CLOCK> Cancel for Timer<'a, CLOCK>
where CLOCK: Clock,

§

type Error = TimerError

Error returned when a countdown can’t be canceled.
source§

fn cancel(&mut self) -> Result<(), Self::Error>

Tries to cancel this countdown. Read more
source§

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

source§

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

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

impl<'a, CLOCK> CountDown for Timer<'a, CLOCK>
where CLOCK: Clock,

§

type Time = Duration

The unit of time used by this timer
source§

fn start<T: Into<Self::Time>>(&mut self, duration: T)

Starts a new count down
source§

fn wait(&mut self) -> Result<(), Void>

Non-blockingly “waits” until the count down finishes Read more

Auto Trait Implementations§

§

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

§

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

§

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.