pub struct Timer { /* private fields */ }Expand description
Explicitly ticked timer with pause, reset and exact duration accounting. A zero-duration timer completes once per non-paused tick, including a zero tick.
Implementations§
Source§impl Timer
impl Timer
Sourcepub fn new(duration: Duration, mode: TimerMode) -> Self
pub fn new(duration: Duration, mode: TimerMode) -> Self
Creates an unpaused timer at zero elapsed time.
Sourcepub fn once(seconds: f32) -> Option<Self>
pub fn once(seconds: f32) -> Option<Self>
Creates a one-shot timer from finite non-negative seconds.
Invalid or unrepresentable durations return None.
Sourcepub fn repeating(seconds: f32) -> Option<Self>
pub fn repeating(seconds: f32) -> Option<Self>
Creates a repeating timer from finite non-negative seconds.
Sourcepub fn tick(&mut self, delta: Duration) -> &mut Self
pub fn tick(&mut self, delta: Duration) -> &mut Self
Advances time and replaces this tick’s completion count. Paused ticks clear completion pulses while preserving elapsed time and the sticky finished state of one-shot timers.
Sourcepub fn tick_secs(&mut self, seconds: f32) -> &mut Self
pub fn tick_secs(&mut self, seconds: f32) -> &mut Self
Ticks using a script/frame delta in seconds. Invalid deltas are ignored and clear completion edges, so a bad frame cannot poison timer state.
Sourcepub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
Elapsed part of the interval (clamped for one-shot, wrapped for repeating).
Sourcepub fn remaining(&self) -> Duration
pub fn remaining(&self) -> Duration
Time remaining until the next completion. A finished one-shot returns zero.
Sourcepub fn fraction(&self) -> f32
pub fn fraction(&self) -> f32
Progress in [0, 1]; zero-duration timers return one after their first tick.
Sourcepub fn finished(&self) -> bool
pub fn finished(&self) -> bool
Whether a one-shot is complete, or a repeating timer completed this tick.
Sourcepub fn just_finished(&self) -> bool
pub fn just_finished(&self) -> bool
Whether the most recent tick crossed at least one interval.
Sourcepub fn times_finished(&self) -> u64
pub fn times_finished(&self) -> u64
Number of crossed intervals in the last tick, saturating at u64::MAX.
Sourcepub fn set_paused(&mut self, paused: bool)
pub fn set_paused(&mut self, paused: bool)
Suspends or resumes the timer without resetting it.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Clears elapsed/completion state while preserving duration, mode and pause.
Sourcepub fn set_duration(&mut self, duration: Duration)
pub fn set_duration(&mut self, duration: Duration)
Replaces the interval and resets progress, preserving mode and pause.
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> MaybeSync for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.