iet-rate-limit-core
Defines the transport- and backend-neutral request admission contract.
iet-rate-limit-corecontractRate-limit contractHow to use it
iet-rate-limit-core is the transport- and backend-neutral admission contract: RatePolicy (a validated prefix/limit/window), RateLimitConfig (per-route fixed or disabled), RateLimit (the check port), RateDecision, and the Unlimited default. The iet-rate-limit feature crate is the cache-backed implementation; this crate fixes the shape it must satisfy.
// crates/core/iet-rate-limit-core/src/lib.rs (contract used by crates/features/iet-rate-limit)
use ;
use Duration;
// Registration validates limit/window; `None` means the route is not limited.
let policy = fixed
.policy?
.expect;
assert!;
// `Unlimited` is the fail-open default for a host with no limiter configured.
match Unlimited.check.await?
RatePolicy::newrejects an empty id,limit == 0,limit == u64::MAX, or a zero window withrate_limit.policy.RateLimitConfig::disabled()yields no policy;Defaultisfixed(120, 60s). The subject string must not contain credentials.
How it works
A typed RateLimitConfig is turned into a RatePolicy (or None when disabled); a RateLimit implementation consumes the policy and returns a RateDecision, with Unlimited as the always-allow default.
flowchart LR A["RateLimitConfig::fixed or disabled"] --> B["policy id"] B --> C["RatePolicy prefix limit window"] C --> D["RateLimit::check subject"] D --> E["RateDecision::Allowed"] D --> F["RateDecision::Denied"] G["Unlimited"] --> E
Core contract
This page is the crate reference. For the framework-wide runtime and trait model, read Architecture.
What it implements
- Defines the traits other crates implement:
RateLimit.
What's inside
Modules
src/lib.rs
Public API
(root)
- struct
RatePolicy pub fn prefix(&self) -> &strpub fn limit(&self) -> u64pub fn window(&self) -> Durationpub fn new(id: impl Into<String>, limit: u64, window: Duration) -> AppResult<Self>- struct
RateLimitConfig - const
fn - const
fn pub fn policy(self, id: &str) -> AppResult<Option<RatePolicy>>- enum
RateDecision - trait
RateLimit
- struct
Unlimited
Impl map
Default for RateLimitConfigRateLimit for Unlimited
Depends on
Used by
In this repository
- Not used by a checked-in example yet.
Source: crates/core/iet-rate-limit-core