pub struct RuleConfig {
pub interval: Duration,
pub limit: u32,
}
Fields§
§interval: Duration
§limit: u32
Implementations§
Source§impl RuleConfig
impl RuleConfig
Sourcepub fn new(interval: Duration, limit: u32) -> Self
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
impl Clone for RuleConfig
Source§fn clone(&self) -> RuleConfig
fn clone(&self) -> RuleConfig
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for RuleConfig
impl RefUnwindSafe for RuleConfig
impl Send for RuleConfig
impl Sync for RuleConfig
impl Unpin for RuleConfig
impl UnwindSafe for RuleConfig
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