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
impl FixedWindowCounterBuilder
Sourcepub fn builder() -> Self
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());Sourcepub fn window_duration(self, duration: Duration) -> Self
pub fn window_duration(self, duration: Duration) -> Self
Sourcepub fn with_time<T: TimeSource>(
self,
time_source: T,
) -> FixedWindowCounterBuilderWithTime<T>
pub fn with_time<T: TimeSource>( self, time_source: T, ) -> FixedWindowCounterBuilderWithTime<T>
Trait Implementations§
Source§impl Debug for FixedWindowCounterBuilder
impl Debug for FixedWindowCounterBuilder
Auto Trait Implementations§
impl Freeze for FixedWindowCounterBuilder
impl RefUnwindSafe for FixedWindowCounterBuilder
impl Send for FixedWindowCounterBuilder
impl Sync for FixedWindowCounterBuilder
impl Unpin for FixedWindowCounterBuilder
impl UnwindSafe for FixedWindowCounterBuilder
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