RuleConfig

Struct RuleConfig 

Source
pub struct RuleConfig {
    pub interval: Duration,
    pub limit: u32,
}

Fields§

§interval: Duration§limit: u32

Implementations§

Source§

impl RuleConfig

Source

pub fn new(interval: Duration, limit: u32) -> Self

Examples found in repository?
examples/demo.rs (line 135)
131async fn main() {
132    println!("Starting lazy-limit demo...\n");
133
134    init_rate_limiter!(
135        default: RuleConfig::new(Duration::seconds(1), 5),
136        max_memory: Some(64 * 1024 * 1024),
137        routes: [
138            ("/api/login", RuleConfig::new(Duration::minutes(1), 3)),
139            ("/api/public", RuleConfig::new(Duration::seconds(1), 10)),
140            ("/api/premium", RuleConfig::new(Duration::seconds(1), 20)),
141        ]
142    )
143    .await;
144
145    println!("Rate limiter initialized with rules:");
146    println!("  - Global: 5 requests/second");
147    println!("  - /api/login: 3 requests/minute");
148    println!("  - /api/public: 10 requests/second");
149    println!("  - /api/premium: 20 requests/second");
150    println!();
151
152    println!("--- Test 1: Basic Global Rate Limiting ---");
153    test_basic_limit().await;
154    println!();
155
156    println!("--- Test 2: Route-Specific Rules (with Global Limit) ---");
157    test_route_specific().await;
158    println!();
159
160    println!("--- Test 3: Override Mode ---");
161    test_override_mode().await;
162    println!();
163
164    println!("--- Test 4: Multiple Users ---");
165    test_multiple_users().await;
166    println!();
167
168    println!("--- Test 5: Long Interval Rules ---");
169    test_long_interval().await;
170    println!();
171
172    println!("All demo tests completed.");
173}

Trait Implementations§

Source§

impl Clone for RuleConfig

Source§

fn clone(&self) -> RuleConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RuleConfig

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.