pub struct Timer { /* private fields */ }Expand description
A simple countdown timer.
Useful for cooldowns, delays, and timed events.
§Example
let mut timer = Timer::from_seconds(2.0, false);
// In update loop:
if timer.tick(delta) {
println!("2 seconds elapsed!");
}Implementations§
Source§impl Timer
impl Timer
Sourcepub fn from_seconds(seconds: f64, repeating: bool) -> Self
pub fn from_seconds(seconds: f64, repeating: bool) -> Self
Create a timer with the given duration.
Sourcepub fn tick(&mut self, delta: f64) -> bool
pub fn tick(&mut self, delta: f64) -> bool
Advance the timer by delta seconds. Returns true when it fires.
Sourcepub fn set_duration(&mut self, seconds: f64)
pub fn set_duration(&mut self, seconds: f64)
Set a new duration and reset.
Sourcepub fn is_finished(&self) -> bool
pub fn is_finished(&self) -> bool
Whether the timer has finished (non-repeating only).
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Whether the timer is still running.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Timer
impl RefUnwindSafe for Timer
impl Send for Timer
impl Sync for Timer
impl Unpin for Timer
impl UnsafeUnpin for Timer
impl UnwindSafe for Timer
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