pub struct Counter {
pub starting: isize,
pub current: isize,
pub step: isize,
pub limit: Option<isize>,
}Expand description
A little versatile Counter.
Fields
starting: isizeThe starting value.
current: isizeThe current value.
step: isizeThe amount to increase the current value on each
update, until it reaches its limit.
limit: Option<isize>An optional limit value that, when reached, will prevent further updating the counter.
If set, it must have the same sign as the step. If not set,
the natural limit will be |isize::MAX|.
Implementations
sourceimpl Counter
impl Counter
sourcepub fn new(value: isize, step: isize, limit: Option<isize>) -> Self
pub fn new(value: isize, step: isize, limit: Option<isize>) -> Self
Returns a new Counter.
Note that limit and step must be both positive or negative together.
sourcepub fn update(&mut self) -> bool
pub fn update(&mut self) -> bool
If a limit value has been set, returns true when the counter has
reached its limit value, and if not, increments its current value.
If there’s no limit value, always returns false while incrementing
the current value.
sourcepub fn wrapping_update(&mut self) -> bool
pub fn wrapping_update(&mut self) -> bool
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Counter
impl Send for Counter
impl Sync for Counter
impl Unpin for Counter
impl UnwindSafe for Counter
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more