pub struct Timer<S: TimerState> { /* private fields */ }Expand description
Timer which can either be in a paused state or a running state.
To instantiate the timer run Timer::new().
To actually start it call Timer::init()
§Example
use zentime_rs_timer::timer::{Timer, TimerEndHandler, TimerTickHandler, TimerStatus, Paused};
use zentime_rs_timer::TimerAction;
use std::thread;
// Handler which is passed to our timer implementation
pub struct OnEndHandler { }
impl TimerEndHandler for OnEndHandler {
fn call(&mut self) {
println!("Hi from timer");
}
}
pub struct OnTickHandler {}
impl TimerTickHandler for OnTickHandler {
fn call(&mut self, status: TimerStatus) -> Option<TimerAction> {
println!("{}", status.current_time);
None
}
}
// Run timer in its own thread so it does not block the current one
thread::spawn(move || {
Timer::<Paused>::new(
10,
Some(OnEndHandler {}),
Some(OnTickHandler {})
)
.init();
});Implementations§
Source§impl Timer<Paused>
impl Timer<Paused>
Sourcepub fn new<E, T>(time: u64, on_timer_end: Option<E>, on_tick: Option<T>) -> Selfwhere
E: TimerEndHandler + 'static,
T: TimerTickHandler + 'static,
pub fn new<E, T>(time: u64, on_timer_end: Option<E>, on_tick: Option<T>) -> Selfwhere
E: TimerEndHandler + 'static,
T: TimerTickHandler + 'static,
Creates a new timer in paused state. You have to call Self::init() to start the timer
Source§impl Timer<Running>
impl Timer<Running>
Sourcepub fn new<E, T>(time: u64, on_timer_end: Option<E>, on_tick: Option<T>) -> Selfwhere
E: TimerEndHandler + 'static,
T: TimerTickHandler + 'static,
pub fn new<E, T>(time: u64, on_timer_end: Option<E>, on_tick: Option<T>) -> Selfwhere
E: TimerEndHandler + 'static,
T: TimerTickHandler + 'static,
Creates a new timer in paused state. You have to call Self::init() to start the timer
Trait Implementations§
Auto Trait Implementations§
impl<S> Freeze for Timer<S>where
S: Freeze,
impl<S> !RefUnwindSafe for Timer<S>
impl<S> !Send for Timer<S>
impl<S> !Sync for Timer<S>
impl<S> Unpin for Timer<S>where
S: Unpin,
impl<S> !UnwindSafe for Timer<S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more