pub struct SlidingWindow {
pub window_seconds: u64,
pub granularity_seconds: u64,
}
Expand description
A sliding window.
Fields§
§window_seconds: u64
The number of seconds to apply the limit to.
granularity_seconds: u64
A number between 1 and window_seconds
. Since window_seconds
is a
sliding window, configure what the granularity of that window is.
If this is equal to window_seconds
, the quota resets to 0 every
window_seconds
. If this is a very small number, the window slides
“more smoothly” at the expense of having much more redis keys.
The number of redis keys required to enforce a quota is window_seconds / granularity_seconds
.
Implementations§
source§impl SlidingWindow
impl SlidingWindow
sourcepub fn iter(&self, timestamp: UnixTimestamp) -> impl Iterator<Item = Slot>
pub fn iter(&self, timestamp: UnixTimestamp) -> impl Iterator<Item = Slot>
Iterate over the quota’s window, yielding values representing each (absolute) granule.
This function is used to calculate keys for storing the number of requests made in each granule.
The iteration is done in natural-order (oldest timestamp to newest),
starting with the key to which a currently-processed request should be
added. That request’s timestamp is request_timestamp
.
request_timestamp / self.granularity_seconds
request_timestamp / self.granularity_seconds + 1
request_timestamp / self.granularity_seconds + 2
- …
sourcepub fn active_slot(&self, timestamp: UnixTimestamp) -> Slot
pub fn active_slot(&self, timestamp: UnixTimestamp) -> Slot
The active bucket is the oldest active granule.
Trait Implementations§
source§impl Clone for SlidingWindow
impl Clone for SlidingWindow
source§fn clone(&self) -> SlidingWindow
fn clone(&self) -> SlidingWindow
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for SlidingWindow
impl Debug for SlidingWindow
source§impl<'de> Deserialize<'de> for SlidingWindow
impl<'de> Deserialize<'de> for SlidingWindow
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>,
source§impl Hash for SlidingWindow
impl Hash for SlidingWindow
source§impl Ord for SlidingWindow
impl Ord for SlidingWindow
source§fn cmp(&self, other: &SlidingWindow) -> Ordering
fn cmp(&self, other: &SlidingWindow) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for SlidingWindow
impl PartialEq for SlidingWindow
source§impl PartialOrd for SlidingWindow
impl PartialOrd for SlidingWindow
source§impl Serialize for SlidingWindow
impl Serialize for SlidingWindow
impl Copy for SlidingWindow
impl Eq for SlidingWindow
impl StructuralPartialEq for SlidingWindow
Auto Trait Implementations§
impl Freeze for SlidingWindow
impl RefUnwindSafe for SlidingWindow
impl Send for SlidingWindow
impl Sync for SlidingWindow
impl Unpin for SlidingWindow
impl UnwindSafe for SlidingWindow
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more