FixedWindowCounterBuilder

Struct FixedWindowCounterBuilder 

Source
pub struct FixedWindowCounterBuilder { /* private fields */ }
Expand description

Builder for configuring and creating FixedWindowCounter instances.

FixedWindowCounterBuilder provides a fluent interface for configuring all aspects of a fixed window counter rate limiter. The precision and time source types are determined through the builder chain.

Implementations§

Source§

impl FixedWindowCounterBuilder

Source

pub fn builder() -> Self

Creates a new builder for configuring a FixedWindowCounter.

This is the preferred way to start building a FixedWindowCounter.

§Returns

A new FixedWindowCounterBuilder ready for configuration

§Examples
use rate_guard::{Millis, MockTimeSource, RateLimit};
use rate_guard::limits::FixedWindowCounterBuilder;
use std::time::Duration;

let counter = FixedWindowCounterBuilder::builder()
    .capacity(100)
    .window_duration(Duration::from_secs(60))
    .with_time(MockTimeSource::new())
    .with_precision::<Millis>()
    .build()
    .unwrap();

assert!(counter.try_acquire(50).is_ok());
Source

pub fn capacity(self, capacity: Uint) -> Self

Sets the maximum capacity of the fixed window counter.

The capacity determines the maximum number of actions allowed within each fixed window.

§Arguments
  • capacity - Maximum number of actions allowed per window
§Returns

Self for method chaining

Source

pub fn window_duration(self, duration: Duration) -> Self

Sets the duration of each fixed window.

This determines how long each window lasts before resetting. Common values include minutes or hours for rate limiting APIs.

§Arguments
  • duration - Duration of each fixed window
§Returns

Self for method chaining

Source

pub fn with_time<T: TimeSource>( self, time_source: T, ) -> FixedWindowCounterBuilderWithTime<T>

Configures the time source for the fixed window counter.

This method sets the time source and returns a builder that can then configure the precision type.

§Arguments
  • time_source - The time source instance to use
§Returns

A builder with time source configured

Trait Implementations§

Source§

impl Debug for FixedWindowCounterBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FixedWindowCounterBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.