1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use ;
/// A simple rate limiter.
///
/// This rate limiter is useful for limiting the rate at
/// which an action can be performed.
///
/// Note that, regardless of `period`, the first action
/// will always be allowed.
///
/// # Examples
///
/// ```rust
/// let mut ratelimit = Ratelimit::new(Duration::from_secs(1));
/// let mut actions = 0;
///
/// for _ in 0..3 {
/// if ratelimit.check() {
/// actions += 1;
/// }
///
/// sleep(Duration::from_millis(600));
/// }
///
/// assert_eq!(actions, 2);
/// ```