[][src]Struct ticktock::timer::Timer

pub struct Timer<F, V, R> where
    F: Fn(Duration, &mut V) -> R, 
{ /* fields omitted */ }

Methods

impl<F, V, R> Timer<F, V, R> where
    F: Fn(Duration, &mut V) -> R, 
[src]

pub fn apply(func: F, initial: V) -> TimerBuilder<F, V, R>[src]

Construct new timer

The timer will periodically execute F, which will alter a value initially set to V.

F will be passed the elapsed time since the last execution as an argument. F may return a calculated result from updating.

pub fn interval(&self) -> Duration[src]

Get timer interval

pub fn set_value(&mut self, value: V)[src]

Replace the stored value

pub fn update(&mut self, now: Instant) -> Option<R>[src]

Execute function and calculate next execution instant

If now is less than the next execution instant, i.e. execution is not yet due, the function is not called, and None is returned.

Otherwise, the the next execution instant is calculated, the function called and the new value returned.

impl<F, V: Clone, R> Timer<F, V, R> where
    F: Fn(Duration, &mut V) -> R, 
[src]

pub fn value(&self) -> V[src]

Returns a copy of the value stored inside timer.

Trait Implementations

impl<F, V, R> AsMut<V> for Timer<F, V, R> where
    F: Fn(Duration, &mut V) -> R, 
[src]

impl<F, V, R> AsRef<V> for Timer<F, V, R> where
    F: Fn(Duration, &mut V) -> R, 
[src]

impl<F: Debug, V: Debug, R: Debug> Debug for Timer<F, V, R> where
    F: Fn(Duration, &mut V) -> R, 
[src]

Auto Trait Implementations

impl<F, V, R> RefUnwindSafe for Timer<F, V, R> where
    F: RefUnwindSafe,
    V: RefUnwindSafe

impl<F, V, R> Send for Timer<F, V, R> where
    F: Send,
    V: Send

impl<F, V, R> Sync for Timer<F, V, R> where
    F: Sync,
    V: Sync

impl<F, V, R> Unpin for Timer<F, V, R> where
    F: Unpin,
    V: Unpin

impl<F, V, R> UnwindSafe for Timer<F, V, R> where
    F: UnwindSafe,
    V: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.