rusty_rl/
lib.rs

1use std::{
2    collections::HashMap,
3    time::{Duration, Instant},
4};
5mod bucket;
6mod fixed;
7mod fixed_bucket;
8
9///
10///
11
12/// fixed bucket
13///
14/// ```
15///     let b = FixedBucket::new(600, 10).bucket(90, 10.0)
16/// ```
17///
18/// ```
19///     b.allow(unique value) // boolean
20/// ```
21
22pub struct FixedLimit {
23    maximum_request: usize,
24    duration: Duration,
25    requests: HashMap<String, (usize, Instant)>,
26}
27
28pub struct Selfb {
29    pub remaning_count: u64,
30    pub is_allowed: bool,
31}
32
33pub struct TokenBucket {
34    capacity: u64,
35    rates: f64,
36    last_update: HashMap<String, (f64, Instant)>,
37}
38
39pub struct FixedBucket {
40    request: u64,
41    duration: Duration,
42    capacity: u64,
43    rates: f64,
44    last_update: HashMap<String, (f64, Instant)>,
45    requests: HashMap<String, (u64, Instant)>,
46}