operations capa

operations-rate-limit

Rate limiting for Rust applications

Rate limiting for Rust applications

Tieroperations
Roleunclassified (baselined)
Pathcrates/operations/rate-limit
Edition2021
Targetsoperations_rate_limit
Public items36 across 0 modules
Tests19

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`

ItemWhat it is
pub enum RateLimitErrorErrors that can occur with rate limiting.
pub type Result<T>: std::result::Result <T, RateLimitError>Result type for rate limit operations.
pub enum AlgorithmRate limit algorithm.
Algorithm :: fn fmt(& self, f : & mut std::fmt::Formatter <'_>) -> std::fmt::Result
pub struct RateLimitConfigRate limit configuration.
RateLimitConfig :: fn new(max_requests : u64, window_seconds : u64) -> SelfCreates a new rate limit config.
RateLimitConfig :: fn per_second(max : u64) -> SelfCreates a per-second rate limit.
RateLimitConfig :: fn per_minute(max : u64) -> SelfCreates a per-minute rate limit.
RateLimitConfig :: fn per_hour(max : u64) -> SelfCreates a per-hour rate limit.
RateLimitConfig :: fn per_day(max : u64) -> SelfCreates a per-day rate limit.
RateLimitConfig :: fn with_algorithm(mut self, algorithm : Algorithm) -> SelfSets the algorithm.
RateLimitConfig :: fn with_burst(mut self, capacity : u64) -> SelfSets burst capacity.
RateLimitConfig :: fn without_headers(mut self) -> SelfDisables headers.
pub struct RateLimitResultRate limit check result.
RateLimitResult :: fn allowed(remaining : u64, limit : u64, reset_at : DateTime <Utc>) -> SelfCreates an allowed result.
RateLimitResult :: fn denied(limit : u64, reset_at : DateTime <Utc>) -> SelfCreates a denied result.
RateLimitResult :: fn headers(& self) -> HashMap <String, String>Returns HTTP headers for the result.
pub struct RateLimitKeyRate limiter key identifying what's being limited.
RateLimitKey :: fn new(key_type : impl Into <String>, value : impl Into <String>) -> SelfCreates a new rate limit key.
RateLimitKey :: fn ip(addr : impl Into <String>) -> SelfCreates an IP-based key.
RateLimitKey :: fn user(user_id : impl Into <String>) -> SelfCreates a user-based key.
RateLimitKey :: fn api_key(key : impl Into <String>) -> SelfCreates an API key-based key.
RateLimitKey :: fn with_resource(mut self, resource : impl Into <String>) -> SelfAdds a resource scope.
RateLimitKey :: fn to_key_string(& self) -> StringReturns the full key string.
pub struct InMemoryRateLimiterIn-memory rate limiter.
InMemoryRateLimiter :: fn new(config : RateLimitConfig) -> SelfCreates a new in-memory rate limiter.
InMemoryRateLimiter :: fn check(& self, key : & RateLimitKey) -> RateLimitResultChecks if a request is allowed.
InMemoryRateLimiter :: fn record(& self, key : & RateLimitKey) -> RateLimitResultRecords a request (consumes quota).
InMemoryRateLimiter :: fn reset(& self, key : & RateLimitKey)Resets the rate limit for a key.
pub struct RateLimitTierRate limit tier configuration.
RateLimitTier :: fn new(name : impl Into <String>) -> SelfCreates a new tier.
RateLimitTier :: fn with_limit(mut self, config : RateLimitConfig) -> SelfAdds a limit.
RateLimitTier :: fn free() -> SelfCreates a free tier.
RateLimitTier :: fn basic() -> SelfCreates a basic tier.
RateLimitTier :: fn pro() -> SelfCreates a pro tier.
RateLimitTier :: fn enterprise() -> SelfCreates 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)
Locationcrates/operations/rate-limit
Vocabulary in force (lexicon)current

Dependencies

Runtime, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
chrono^0.4serdenoalways
serde^1derivenoalways
serde_json^1noalways
thiserror^2noalways

Development, from outside the workspace.

CrateRequirementFeaturesOptionalOnly on
tokio^1fullnoalways

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

KindNameSource
liboperations_rate_limit`src/lib.rs`

Error model

Error typeNamed by
RateLimitErrorResult

Operational characteristics

PropertyEvidence
async public surfacenone detected
async runtimenone detected
database accessnone detected
network I/Onone detected
unsafe codenone detected
environment variablesnone 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.

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

KindCount
Unit tests19
Integration tests0
Examples0
Doctests0

Evidence by module. How often each public module is named by something executable.

ModuleTestsExamplesConsumers
crate root8025

What the tests establish, by name:

Documentation coverage

MeasureDocumentedTotal
Public items with rustdoc3536
Public modules with a //! block00
pie showData
    title Public items with rustdoc
    "Documented" : 35
    "No rustdoc detected" : 1

Metrics

MetricValue
Rust source files1
Source lines777
Code lines589
Public API items36
Public modules0
Tests19
Examples0
Cargo features0
Direct runtime dependencies4
Workspace reverse dependencies8
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.

Todas las operations · Manual