4 releases
0.1.3 | Nov 26, 2024 |
---|---|
0.1.2 | Nov 25, 2024 |
0.1.1 | Nov 25, 2024 |
0.1.0 | Nov 25, 2024 |
#328 in Math
423 downloads per month
6KB
Bounded Counter
Generic Incremental Bounded Counter
Description
The BoundedCounter
is a generic type that provides an incremental counter with a type specified upper bound.
It increments every time it is iterated until it reaches the upper bound, at which point it resets back to 0.
Usage
use bounded_counter::BoundedCounter;
fn main() {
type Int = i32;
const MOD: Int = Int::MAX / 100;
for int in BoundedCounter::<Int>::default() {
if int % MOD == 0 {
println!("{:.0}%", int / MOD);
}
if int == Int::MAX {
break;
}
}
}
Features
constructor
: Usesderive_more
to derive anew
constructor impl.deref_mut
: Usesderive_more
to derive a mutable deref impl.deref
: Usesderive_more
to derive a deref impl.
Numbers
Type | Max |
---|---|
i8 | 127 |
u8 | 255 |
i16 | 32k |
u16 | 64k |
i32 | 2b |
u32 | 4b |
i64 | 9q |
u64 | 18q |
i128 | 170u |
u128 | 340u |
- k = thousand
- b = billion
- q = quadrillion
- u = quintillion
Dependencies
~93–270KB