pub struct Countdown { /* private fields */ }Expand description
A timer that fires once, after length steps or turns, and waits to be
restarted.
It is the cooldown too. Advance it by 1 each step or turn, and:
use shuyi_core::timer::Countdown;
// Ready for its first use, then two turns' wait.
let mut cooldown = Countdown::new_ready(2);
let mut uses = 0;
for used in [true, true, false, true] {
if used && cooldown.ready() {
uses += 1;
cooldown.restart();
}
cooldown.advance(1);
}
assert_eq!(uses, 2);The default has a length of 0 and is ready.
Implementations§
Source§impl Countdown
impl Countdown
Sourcepub const fn new_ready(length: u32) -> Self
pub const fn new_ready(length: u32) -> Self
One done already, for a cooldown whose first use goes through.
Sourcepub fn advance(&mut self, n: u32) -> bool
pub fn advance(&mut self, n: u32) -> bool
Takes n off what is left, stopping at 0. true only on the call
that takes it from above 0 to 0, so it fires once however far n
overshoots, and advance(0) never fires. A length of 0 is ready at
once and never fires.
Trait Implementations§
impl Copy for Countdown
Source§impl<'de> Deserialize<'de> for Countdown
impl<'de> Deserialize<'de> for Countdown
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Countdown
impl StructuralPartialEq for Countdown
Auto Trait Implementations§
impl Freeze for Countdown
impl RefUnwindSafe for Countdown
impl Send for Countdown
impl Sync for Countdown
impl Unpin for Countdown
impl UnsafeUnpin for Countdown
impl UnwindSafe for Countdown
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