tower_limit/rate/rate.rs
1use std::time::Duration;
2
3/// A rate of requests per time period.
4#[derive(Debug, Copy, Clone)]
5pub struct Rate {
6 num: u64,
7 per: Duration,
8}
9
10impl Rate {
11 /// Create a new rate.
12 ///
13 /// # Panics
14 ///
15 /// This function panics if `num` or `per` is 0.
16 pub fn new(num: u64, per: Duration) -> Self {
17 assert!(num > 0);
18 assert!(per > Duration::from_millis(0));
19
20 Rate { num, per }
21 }
22
23 pub(crate) fn num(&self) -> u64 {
24 self.num
25 }
26
27 pub(crate) fn per(&self) -> Duration {
28 self.per
29 }
30}