#[non_exhaustive]pub enum Algorithm {
TokenBucket,
LeakyBucket,
FixedWindow,
SlidingWindowLog,
SlidingWindowCounter,
}Expand description
Selects the algorithm a limiter uses to decide a request.
Every algorithm shares the same Limiter surface, so the
strategy can change without touching call sites. This enum is the selector a
future builder uses to pick between them.
#[non_exhaustive]: algorithms are added over the 0.x series, so a match
must include a wildcard arm. TokenBucket — the default
— is always available; the leaky bucket and the window algorithms are
compiled in under the algorithms feature, so their variants only exist when
it is enabled.
§Examples
use rate_net::Algorithm;
// The default is the token bucket — smooth refill with burst headroom.
assert_eq!(Algorithm::default(), Algorithm::TokenBucket);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
TokenBucket
Smooth refill with burst headroom up to the configured capacity. The
general-purpose default; delegates its accounting to better-bucket.
LeakyBucket
Constant-drain shaping that smooths bursts to a steady output rate.
Requires the algorithms feature.
FixedWindow
A counter that resets each window; cheapest, tolerates boundary bursts.
Requires the algorithms feature.
SlidingWindowLog
Exact request timestamps within the trailing window; highest accuracy,
higher memory. Requires the algorithms feature.
SlidingWindowCounter
A weighted blend of the current and previous window; an accuracy/cost
balance and a common production choice. Requires the algorithms feature.