pub struct RateLimitBuilder<K, S = (), P = u64, F = DefaultResponseFactory> { /* private fields */ }Expand description
Builder for a rate-limit layer with compile-time store/resolver/factory types.
Implementations§
Source§impl<K, S, P, F> RateLimitBuilder<K, S, P, F>
impl<K, S, P, F> RateLimitBuilder<K, S, P, F>
Sourcepub fn with_store<S2>(self, store: S2) -> RateLimitBuilder<K, S2, P, F>
pub fn with_store<S2>(self, store: S2) -> RateLimitBuilder<K, S2, P, F>
Inject the rate-limit store and update the builder’s store type state.
Sourcepub fn limit(self, limit: u64) -> RateLimitBuilder<K, S, u64, F>
pub fn limit(self, limit: u64) -> RateLimitBuilder<K, S, u64, F>
Set a fixed quota limit and update the provider type state.
Sourcepub fn limit_provider<P2>(
self,
limit_provider: P2,
) -> RateLimitBuilder<K, S, P2, F>
pub fn limit_provider<P2>( self, limit_provider: P2, ) -> RateLimitBuilder<K, S, P2, F>
Replace the fixed provider with a custom asynchronous limit provider.
Sourcepub fn response_factory<F2>(
self,
response_factory: F2,
) -> RateLimitBuilder<K, S, P, F2>
pub fn response_factory<F2>( self, response_factory: F2, ) -> RateLimitBuilder<K, S, P, F2>
Replace the response factory and update its type state.
Sourcepub fn policy_name(self, policy_name: impl Into<String>) -> Self
pub fn policy_name(self, policy_name: impl Into<String>) -> Self
Set the stable policy identifier used in the scoped key and response metadata.
Sourcepub fn with_key_encoder<E>(self, encoder: E) -> Self
pub fn with_key_encoder<E>(self, encoder: E) -> Self
Encode the scoped key before passing it to the crate::Store.
The callback runs in the middleware future’s polling path. It must be deterministic, non-blocking, free of I/O, collision-resistant for the caller’s key space, and non-panicking. Without this method, the complete scoped key is passed to the Store unchanged.
Sourcepub fn skip<Predicate>(self, predicate: Predicate) -> Self
pub fn skip<Predicate>(self, predicate: Predicate) -> Self
Bypass rate limiting when predicate returns true for the request.
The predicate receives the request head and extensions with a unit body. It runs synchronously before client-key extraction and must be non-blocking, free of I/O, and non-panicking. A bypassed request calls the inner service without resolving a limit, charging the Store, or adding rate-limit context or response fields.
Sourcepub fn store_failure_mode(self, mode: StoreFailureMode) -> Self
pub fn store_failure_mode(self, mode: StoreFailureMode) -> Self
Select the mode to use when the Store fails.
Sourcepub fn store_failure_tracing_level(self, level: Level) -> Self
pub fn store_failure_tracing_level(self, level: Level) -> Self
Select the tracing level used for Store failure events.
This configuration is available with the tracing Cargo feature. The default is
tracing::Level::WARN. It affects both StoreFailureMode::Allow and
StoreFailureMode::Reject events.
Sourcepub fn rate_limit_fields(self, fields: RateLimitFields) -> Self
pub fn rate_limit_fields(self, fields: RateLimitFields) -> Self
Select the Rate Limit Fields revision emitted in responses.
Source§impl<K, S, P, F> RateLimitBuilder<K, S, P, F>where
S: Store,
P: LimitProvider,
impl<K, S, P, F> RateLimitBuilder<K, S, P, F>where
S: Store,
P: LimitProvider,
Sourcepub fn build(self) -> Result<RateLimitLayer<K, S, P, F>, ConfigError>
pub fn build(self) -> Result<RateLimitLayer<K, S, P, F>, ConfigError>
Validate the builder and produce a configured layer.