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.
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 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.
Trait Implementations§
Source§impl Clone for FixedWindowPolicy
impl Clone for FixedWindowPolicy
Source§fn clone(&self) -> FixedWindowPolicy
fn clone(&self) -> FixedWindowPolicy
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FixedWindowPolicy
impl Debug for FixedWindowPolicy
impl Eq for FixedWindowPolicy
Source§impl Hash for FixedWindowPolicy
impl Hash for FixedWindowPolicy
Source§impl PartialEq for FixedWindowPolicy
impl PartialEq for FixedWindowPolicy
impl StructuralPartialEq for FixedWindowPolicy
Auto Trait Implementations§
impl Freeze for FixedWindowPolicy
impl RefUnwindSafe for FixedWindowPolicy
impl Send for FixedWindowPolicy
impl Sync for FixedWindowPolicy
impl Unpin for FixedWindowPolicy
impl UnsafeUnpin for FixedWindowPolicy
impl UnwindSafe for FixedWindowPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more