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
use crate::storage::StorageError;
/// Something worth reporting that happened while rate limiting a request.
///
/// Delivered to the callback set with
/// [`TierLimitLayer::on_event`](crate::TierLimitLayer::on_event), for example
/// to log or count it. New variants may be added in minor releases.
#[derive(Debug)]
#[non_exhaustive]
pub enum LimitEvent<'a> {
/// The storage backend failed. The request was then handled by the
/// [`OnStorageError`](crate::OnStorageError) policy.
#[non_exhaustive]
StorageError {
/// The identified user.
user_id: &'a str,
/// The tier whose quota was being checked.
tier: &'a str,
/// The error returned by the backend.
error: &'a StorageError,
},
/// The identifier returned a tier that is not configured. The request was
/// then handled by the [`OnUnknownTier`](crate::OnUnknownTier) policy.
#[non_exhaustive]
UnknownTier {
/// The identified user.
user_id: &'a str,
/// The tier name the identifier returned.
tier: &'a str,
},
/// A request cost more than the tier allows in a whole window, so it was
/// rejected without touching storage.
#[non_exhaustive]
CostExceedsLimit {
/// The identified user.
user_id: &'a str,
/// The tier whose quota applied.
tier: &'a str,
/// The cost of the rejected request.
cost: u32,
/// The tier's maximum burst.
limit: u32,
},
}