Skip to main content

codlet_core/auth/
norate.rs

1//! `NoRateLimit` — a no-op [`RateLimitStore`] for hosts that opt out of
2//! codlet-managed rate limiting.
3//!
4//! Satisfies the [`RateLimitStore`] bound without performing any I/O. Use this
5//! as the `RL` type parameter of [`super::code::CodeAuth`] when the host
6//! provides its own rate limiting at the network or application layer.
7
8use crate::store::error::StoreError;
9use crate::store::ratelimit::{RateLimitKey, RateLimitOutcome, RateLimitPolicy, RateLimitStore};
10
11/// A no-op rate-limit store. Every `check` returns `Allow`; every
12/// `record_failure` and `clear_failures` is a no-op.
13#[derive(Debug, Default, Clone, Copy)]
14pub struct NoRateLimit;
15
16impl RateLimitStore for NoRateLimit {
17    async fn check(
18        &self,
19        _key: &RateLimitKey,
20        _policy: &RateLimitPolicy,
21    ) -> Result<RateLimitOutcome, StoreError> {
22        Ok(RateLimitOutcome::Allow)
23    }
24
25    async fn record_failure(
26        &self,
27        _key: &RateLimitKey,
28        _policy: &RateLimitPolicy,
29    ) -> Result<(), StoreError> {
30        Ok(())
31    }
32
33    async fn clear_failures(&self, _key: &RateLimitKey) -> Result<(), StoreError> {
34        Ok(())
35    }
36}