pub struct FixedWindowPolicy { /* private fields */ }Expand description
An anchored fixed-window rate-limit policy.
A backend starts a window on the first allowed check for a storage key. Later allowed checks use that anchor until the full window has elapsed. This differs from fixed wall-clock boundaries such as calendar minutes.
Windows have exact whole-millisecond precision. A policy owns its application-defined identifier and scope so it can be reused by checks.
With the serde feature, the wire object contains id, scope, limit,
window_millis, and quota_mode. The derived fingerprint is deliberately
omitted and recomputed through FixedWindowPolicy::new when
deserializing. An omitted quota_mode defaults to enforcement.
Implementations§
Source§impl FixedWindowPolicy
impl FixedWindowPolicy
Sourcepub fn new(
id: PolicyId,
scope: ScopeId,
limit: u64,
window: Duration,
) -> Result<Self, PolicyError>
pub fn new( id: PolicyId, scope: ScopeId, limit: u64, window: Duration, ) -> Result<Self, PolicyError>
Validates and constructs an anchored fixed-window policy.
§Errors
Returns an error if limit or window is zero, if limit exceeds
MAX_LIMIT, if the window is not an exact whole number of
milliseconds, or if it exceeds MAX_WINDOW.
Sourcepub const fn with_quota_mode(self, quota_mode: QuotaMode) -> Self
pub const fn with_quota_mode(self, quota_mode: QuotaMode) -> Self
Returns this policy with the requested quota deployment mode.
The policy fingerprint is unchanged because the mode is not storage-relevant.
Sourcepub const fn window_millis(&self) -> u64
pub const fn window_millis(&self) -> u64
Returns the anchored window as an exact, nonzero millisecond count.
Sourcepub const fn fingerprint(&self) -> PolicyFingerprint
pub const fn fingerprint(&self) -> PolicyFingerprint
Returns the deterministic configuration fingerprint.
Sourcepub const fn quota_mode(&self) -> QuotaMode
pub const fn quota_mode(&self) -> QuotaMode
Returns whether quota exhaustion is enforced or shadowed.
Trait Implementations§
Source§impl Clone for FixedWindowPolicy
impl Clone for FixedWindowPolicy
Source§fn clone(&self) -> FixedWindowPolicy
fn clone(&self) -> FixedWindowPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FixedWindowPolicy
impl Debug for FixedWindowPolicy
Source§impl<'de> Deserialize<'de> for FixedWindowPolicy
Available on crate feature serde only.
impl<'de> Deserialize<'de> for FixedWindowPolicy
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
impl Eq for FixedWindowPolicy
Source§impl Hash for FixedWindowPolicy
impl Hash for FixedWindowPolicy
Source§impl PartialEq for FixedWindowPolicy
impl PartialEq for FixedWindowPolicy
Source§impl RateLimitPolicy for FixedWindowPolicy
impl RateLimitPolicy for FixedWindowPolicy
Source§fn quota(&self) -> u64
fn quota(&self) -> u64
Self::quota_period.Source§fn quota_period(&self) -> Duration
fn quota_period(&self) -> Duration
Self::quota is replenished.Source§fn capacity(&self) -> u64
fn capacity(&self) -> u64
Source§fn fingerprint(&self) -> PolicyFingerprint
fn fingerprint(&self) -> PolicyFingerprint
Source§fn quota_mode(&self) -> QuotaMode
fn quota_mode(&self) -> QuotaMode
Source§impl Serialize for FixedWindowPolicy
Available on crate feature serde only.
impl Serialize for FixedWindowPolicy
serde only.