box-counter
English | 简体中文
box-counter provides a concurrent counter with optional rate tracking. Supports both multi-threaded (Counter via Arc) and single-threaded (LocalCounter via Rc) variants.
Features
- Count mode — track current value and maximum reached
- Rate mode — track total count and per-second throughput rate
- Thread-safe
Counter(Arc-based) and lightweightLocalCounter(Rc-based) - Serialize/Deserialize support via
postcard - Auto-updating rate calculation
Cargo Feature Flags
| Feature | Description | Default |
|---|---|---|
count |
Enable current value and max tracking | no |
rate |
Enable throughput rate tracking | no |
At least one feature must be enabled. Enable both for full functionality.
Basic Usage
use Counter;
let c = new; // requires "count" feature
c.inc;
c.incs;
c.dec;
assert_eq!;
assert_eq!;
Rate Mode
use Counter;
use Duration;
let c = new; // requires "rate" feature
c.incs;
sleep;
println!;
Tests
51 tests covering count, rate, combined features, and serialization roundtrip.
License
Licensed under either of Apache License 2.0 or MIT license at your option.