rl_core/
denied.rs

1/// A reason for denial.
2#[derive(Clone,Debug,PartialEq,Eq,PartialOrd,Ord)]
3#[non_exhaustive]
4pub enum Denied<T = std::time::SystemTime> {
5	/// The maximum request was less than the minimum.
6	EmptyRequest,
7	/// The request can not be made at this time due to rate limiting rules.
8	TooEarly(crate::TooEarly<T>),
9	/// The request is larger than the max bucket size and will never be allowed with the current config.
10	///
11	/// Note: [Overfilling](Tracker::overfull()) can allow requests larger than buckets, however this never happens by waiting. It must be done explicitly by the application. Overfilling can allow arbitrarily large requests to succeed on any config.
12	TooBig,
13}
14
15impl<T: std::fmt::Debug> std::fmt::Display for Denied<T> {
16	fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
17		match self {
18			Denied::EmptyRequest => f.write_str("Request maximum is less than minimum."),
19			Denied::TooEarly(err) => err.fmt(f),
20			Denied::TooBig => f.write_str("Request cost is larger than bucket size."),
21		}
22	}
23}
24
25impl<T: std::fmt::Debug> std::error::Error for Denied<T> {}
26
27impl<T> From<crate::TooEarly<T>> for Denied<T> {
28	fn from(e: crate::TooEarly<T>) -> Self {
29		Denied::TooEarly(e)
30	}
31}