Rate limiting for Rust applications
| Tier | operations |
| Role | unclassified (baselined) |
| Path | crates/operations/rate-limit |
| Edition | 2021 |
| Targets | operations_rate_limit |
| Public items | 36 across 0 modules |
| Tests | 19 |
What it is for
Rate limiting library crates for Rust applications.
This crate provides rate limiting algorithms and abstractions for protecting APIs and services from abuse.
Capabilities
Algorithm
Rate limiting library crates for Rust applications.
| Item |
|---|
pub enum Algorithm |
Algorithm :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result |
InMemoryRateLimiter
Rate limiting library crates for Rust applications.
| Item |
|---|
pub struct InMemoryRateLimiter |
InMemoryRateLimiter :: fn new(config : RateLimitConfig) -> Self |
InMemoryRateLimiter :: fn check(& self, key : & RateLimitKey) -> RateLimitResult |
InMemoryRateLimiter :: fn record(& self, key : & RateLimitKey) -> RateLimitResult |
InMemoryRateLimiter :: fn reset(& self, key : & RateLimitKey) |
RateLimitConfig
Rate limiting library crates for Rust applications.
| Item |
|---|
pub struct RateLimitConfig |
RateLimitConfig :: fn new(max_requests : u64, window_seconds : u64) -> Self |
RateLimitConfig :: fn per_second(max : u64) -> Self |
RateLimitConfig :: fn per_minute(max : u64) -> Self |
RateLimitConfig :: fn per_hour(max : u64) -> Self |
RateLimitConfig :: fn per_day(max : u64) -> Self |
RateLimitConfig :: fn with_algorithm(mut self, algorithm : Algorithm) -> Self |
RateLimitConfig :: fn with_burst(mut self, capacity : u64) -> Self |
RateLimitConfig :: fn without_headers(mut self) -> Self |
RateLimitError
Rate limiting library crates for Rust applications.
| Item |
|---|
pub enum RateLimitError |
RateLimitKey
Rate limiting library crates for Rust applications.
| Item |
|---|
pub struct RateLimitKey |
RateLimitKey :: fn new(key_type : impl Into <String>, value : impl Into <String>) -> Self |
RateLimitKey :: fn ip(addr : impl Into <String>) -> Self |
RateLimitKey :: fn user(user_id : impl Into <String>) -> Self |
RateLimitKey :: fn api_key(key : impl Into <String>) -> Self |
RateLimitKey :: fn with_resource(mut self, resource : impl Into <String>) -> Self |
RateLimitKey :: fn to_key_string(& self) -> String |
RateLimitResult
Rate limiting library crates for Rust applications.
| Item |
|---|
pub struct RateLimitResult |
RateLimitResult :: fn allowed(remaining : u64, limit : u64, reset_at : DateTime <Utc>) -> Self |
RateLimitResult :: fn denied(limit : u64, reset_at : DateTime <Utc>) -> Self |
RateLimitResult :: fn headers(& self) -> HashMap <String, String> |
RateLimitTier
Rate limiting library crates for Rust applications.
| Item |
|---|
pub struct RateLimitTier |
RateLimitTier :: fn new(name : impl Into <String>) -> Self |
RateLimitTier :: fn with_limit(mut self, config : RateLimitConfig) -> Self |
RateLimitTier :: fn free() -> Self |
RateLimitTier :: fn basic() -> Self |
RateLimitTier :: fn pro() -> Self |
RateLimitTier :: fn enterprise() -> Self |
Result
Rate limiting library crates for Rust applications.
| Item |
|---|
pub type Result<T>: std::result::Result <T, RateLimitError> |
How to use it
No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.
Module structure
No public modules: the crate root is its whole surface.
Public surface
`crate root`
| Item | What it is |
|---|---|
pub enum RateLimitError | Errors that can occur with rate limiting. |
pub type Result<T>: std::result::Result <T, RateLimitError> | Result type for rate limit operations. |
pub enum Algorithm | Rate limit algorithm. |
Algorithm :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result | — |
pub struct RateLimitConfig | Rate limit configuration. |
RateLimitConfig :: fn new(max_requests : u64, window_seconds : u64) -> Self | Creates a new rate limit config. |
RateLimitConfig :: fn per_second(max : u64) -> Self | Creates a per-second rate limit. |
RateLimitConfig :: fn per_minute(max : u64) -> Self | Creates a per-minute rate limit. |
RateLimitConfig :: fn per_hour(max : u64) -> Self | Creates a per-hour rate limit. |
RateLimitConfig :: fn per_day(max : u64) -> Self | Creates a per-day rate limit. |
RateLimitConfig :: fn with_algorithm(mut self, algorithm : Algorithm) -> Self | Sets the algorithm. |
RateLimitConfig :: fn with_burst(mut self, capacity : u64) -> Self | Sets burst capacity. |
RateLimitConfig :: fn without_headers(mut self) -> Self | Disables headers. |
pub struct RateLimitResult | Rate limit check result. |
RateLimitResult :: fn allowed(remaining : u64, limit : u64, reset_at : DateTime <Utc>) -> Self | Creates an allowed result. |
RateLimitResult :: fn denied(limit : u64, reset_at : DateTime <Utc>) -> Self | Creates a denied result. |
RateLimitResult :: fn headers(& self) -> HashMap <String, String> | Returns HTTP headers for the result. |
pub struct RateLimitKey | Rate limiter key identifying what's being limited. |
RateLimitKey :: fn new(key_type : impl Into <String>, value : impl Into <String>) -> Self | Creates a new rate limit key. |
RateLimitKey :: fn ip(addr : impl Into <String>) -> Self | Creates an IP-based key. |
RateLimitKey :: fn user(user_id : impl Into <String>) -> Self | Creates a user-based key. |
RateLimitKey :: fn api_key(key : impl Into <String>) -> Self | Creates an API key-based key. |
RateLimitKey :: fn with_resource(mut self, resource : impl Into <String>) -> Self | Adds a resource scope. |
RateLimitKey :: fn to_key_string(& self) -> String | Returns the full key string. |
pub struct InMemoryRateLimiter | In-memory rate limiter. |
InMemoryRateLimiter :: fn new(config : RateLimitConfig) -> Self | Creates a new in-memory rate limiter. |
InMemoryRateLimiter :: fn check(& self, key : & RateLimitKey) -> RateLimitResult | Checks if a request is allowed. |
InMemoryRateLimiter :: fn record(& self, key : & RateLimitKey) -> RateLimitResult | Records a request (consumes quota). |
InMemoryRateLimiter :: fn reset(& self, key : & RateLimitKey) | Resets the rate limit for a key. |
pub struct RateLimitTier | Rate limit tier configuration. |
RateLimitTier :: fn new(name : impl Into <String>) -> Self | Creates a new tier. |
RateLimitTier :: fn with_limit(mut self, config : RateLimitConfig) -> Self | Adds a limit. |
RateLimitTier :: fn free() -> Self | Creates a free tier. |
RateLimitTier :: fn basic() -> Self | Creates a basic tier. |
RateLimitTier :: fn pro() -> Self | Creates a pro tier. |
RateLimitTier :: fn enterprise() -> Self | Creates an enterprise tier (unlimited). |
No pub use re-exports: every item above is declared in this crate.
Boundary
Depends on no other workspace tier.
Shares tier operations with 40 other crates: operations-approval-workflow, operations-assessments, operations-block-imaging, operations-boot-media, operations-browser-agent-worker, operations-camera-discovery, operations-camera-liveview, operations-camera-registry, … (40 total).
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | operations |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/operations/rate-limit |
| Vocabulary in force (lexicon) | current |
Dependencies
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
chrono | ^0.4 | serde | no | always |
serde | ^1 | derive | no | always |
serde_json | ^1 | — | no | always |
thiserror | ^2 | — | no | always |
Development, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
tokio | ^1 | full | no | always |
Build. None.
Depended on by. 8 workspace crates.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR n_application_rate_limit["application-rate-limit"] -->|uses| SELF n_application_wiki["application-wiki"] -->|uses| SELF n_infrastructure_acquire["infrastructure-acquire"] -->|uses| SELF n_infrastructure_fetcher["infrastructure-fetcher"] -->|uses| SELF n_infrastructure_web_ingest["infrastructure-web-ingest"] -->|uses| SELF n_operations_link_graph["operations-link-graph"] -->|uses| SELF n_operations_mail_sync["operations-mail-sync"] -->|uses| SELF n_platform_privacy_scan_api["platform-privacy-scan-api"] -->|uses| SELF SELF["operations-rate-limit"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.
Targets
| Kind | Name | Source |
|---|---|---|
| lib | operations_rate_limit | `src/lib.rs` |
Error model
| Error type | Named by |
|---|---|
RateLimitError | Result |
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | none detected |
| async runtime | none detected |
| database access | none detected |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | none detected |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
No environment variable is read with a literal name anywhere in this crate. A variable whose key is computed at run time cannot be listed here, and is not claimed to be absent.
Related capabilities
8 workspace crates depend on this one: application-rate-limit, application-wiki, infrastructure-acquire, infrastructure-fetcher, infrastructure-web-ingest, operations-link-graph, operations-mail-sync, platform-privacy-scan-api.
Verification
| Kind | Count |
|---|---|
| Unit tests | 19 |
| Integration tests | 0 |
| Examples | 0 |
| Doctests | 0 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 8 | 0 | 25 |
What the tests establish, by name:
test_algorithm_display—src/lib.rstest_config_serialization—src/lib.rstest_error_display—src/lib.rstest_fixed_window_limiter—src/lib.rstest_limiter_check_without_record—src/lib.rstest_limiter_reset—src/lib.rstest_rate_limit_config_new—src/lib.rstest_rate_limit_config_shortcuts—src/lib.rstest_rate_limit_config_with_algorithm—src/lib.rstest_rate_limit_key_new—src/lib.rstest_rate_limit_key_shortcuts—src/lib.rstest_rate_limit_key_with_resource—src/lib.rstest_rate_limit_result_allowed—src/lib.rstest_rate_limit_result_denied—src/lib.rstest_rate_limit_result_headers—src/lib.rstest_rate_limit_tier_custom—src/lib.rstest_rate_limit_tier_free—src/lib.rstest_sliding_window_limiter—src/lib.rstest_token_bucket_limiter—src/lib.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 35 | 36 |
Public modules with a //! block | 0 | 0 |
pie showData
title Public items with rustdoc
"Documented" : 35
"No rustdoc detected" : 1
Metrics
| Metric | Value |
|---|---|
| Rust source files | 1 |
| Source lines | 777 |
| Code lines | 589 |
| Public API items | 36 |
| Public modules | 0 |
| Tests | 19 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 4 |
| Workspace reverse dependencies | 8 |
pie showData
title Public API by kind
"enum" : 2
"method" : 28
"struct" : 5
"type alias" : 1
pie showData
title Rust source composition
"Code" : 589
"Blank or comment" : 188
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.