API Reference Guide
This page is a compact API map. The linked concept pages explain behavior and tradeoffs; generated docs.rs documentation contains exhaustive signatures and constructor lists.

Builder
RateLimiterBuilder builds every provider and limiter. Start from the backend. The type that the
caller expects from build() selects the target, and build() returns an Arc of it.
| Backend | Constructor | Feature | Adds | Targets |
|---|---|---|---|---|
LocalBackend | RateLimiterBuilder::local() | none | none | LocalRateLimiterProvider, AbsoluteLocalRateLimiter, SuppressedLocalRateLimiter |
RedisBackend | RateLimiterBuilder::redis(connection) | redis-tokio or redis-smol | prefix | RedisRateLimiterProvider, AbsoluteRedisRateLimiter, SuppressedRedisRateLimiter |
HybridBackend | RateLimiterBuilder::hybrid(connection) | redis-tokio or redis-smol | prefix, sync_interval, allowed_lag, allowed_lag_applies_to_rejections | HybridRateLimiterProvider, AbsoluteHybridRateLimiter, SuppressedHybridRateLimiter |
Each target also has a builder() shortcut with the same arguments as its backend constructor,
for example LocalRateLimiterProvider::builder() or AbsoluteHybridRateLimiter::builder(connection).
A shortcut fixes the target, so its build() needs no annotation. A target of another backend
does not compile. See Backends and targets.
Providers and limiters
| Backend | Keys | Calls |
|---|---|---|
| Local | &str | synchronous |
| Redis | &RedisKey | async |
| Hybrid | &RedisKey | async, except try_inc |
Each provider exposes .absolute() and .suppressed(). A directly built limiter runs one strategy
only. A limiter with a prefix uses the same Redis keys as the strategy of a provider with the same
prefix. See Build one strategy directly.
Shared types
| Type | Role |
|---|---|
RateLimiterBuilder | builder struct for every provider and limiter |
RateLimiterTarget | sealed trait of the types that build() returns; the bound for generic code |
RateLimit | validated rate, normalized per second |
WindowSize, BucketSize | live-history duration and grouping precision |
HardLimitFactor | multiplier from soft target to full suppression |
SuppressionFactorCachePeriod | suppression-factor cache duration |
RateLimitDecision | admission result and rejection metadata |
SuppressedRateLimitSnapshot | suppressed live read |
RateLimitComparator | guard over the current live total |
HistoryPreservation | newest/oldest retention policy |
ConditionalSetOutcome | match status and before/after totals |
RedisKey | validated Redis/hybrid namespace or subject key |
SyncInterval | hybrid synchronization cadence |
AllowedLag | maximum age of hybrid local state for read-only calls |
Operations
inc(...): establish admission, then record allowed usage.is_allowed(...): absolute admission check without increment.get(...): live total or suppressed snapshot; unknown keys return zero without insertion.get_suppression_factor(...): suppressed pressure; unknown keys return0.0.set_rate_limit(...): update an existing sticky rate without replacing live history.delete(...): remove one key and return its live absolute or accepted suppressed usage.clear(): remove every key for the called strategy under its configured prefix.set_if(...): comparator-gated history replacement.set_if_preserve_history(...): comparator-gated update retaining newest or oldest history.start_cleanup_loop(),stop_cleanup_loop(): idempotent cleanup controls on providers and on each limiter. Each limiter has its own loop, and the controls of a provider start and stop the loops of its two limiters. A loop ends at once afterstop_cleanup_loop()or after the lastArcof its limiter drops.window_size(): the window that the provider or limiter was built with, on providers and on each limiter.- Hybrid
get_estimate(...): local estimate when state permits, Redis refresh otherwise. - Hybrid read-only calls (
is_allowed,get_estimate,get_suppression_factor) answer from local state at mostAllowedLagold and record no activity. For a key with no stored limit they keep a small local entry, without a Redis key, until cleanup removes it.
The hybrid builder adds sync_interval(SyncInterval), allowed_lag(AllowedLag), and
allowed_lag_applies_to_rejections(bool). AllowedLag constructors
return TrypemaError::InvalidAllowedLag for zero or an overflowing value.
Reads may lazily evict expired buckets. Matched zero conditional updates remove state. Absolute admission remains best-effort under concurrency.

