Struct ticktock::timer::Timer
[−]
[src]
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]
F: Fn(Duration, &mut V) -> R,
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]
F: Fn(Duration, &mut V) -> R,
Trait Implementations
impl<F: Debug, V: Debug, R: Debug> Debug for Timer<F, V, R> where
F: Fn(Duration, &mut V) -> R,
[src]
F: Fn(Duration, &mut V) -> R,
fn fmt(&self, __arg_0: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more
impl<F, V, R> AsRef<V> for Timer<F, V, R> where
F: Fn(Duration, &mut V) -> R,
[src]
F: Fn(Duration, &mut V) -> R,
impl<F, V, R> AsMut<V> for Timer<F, V, R> where
F: Fn(Duration, &mut V) -> R,
[src]
F: Fn(Duration, &mut V) -> R,