Skip to main content

token_bucket/error/
impl.rs

1use super::*;
2
3/// Formats `RateLimitError` variants as human-readable messages.
4impl fmt::Display for RateLimitError {
5    /// Writes the error description to the given formatter.
6    ///
7    /// # Arguments
8    ///
9    /// - `&Self` - The error variant to format.
10    /// - `&mut fmt::Formatter<'_>` - The target formatter.
11    ///
12    /// # Returns
13    ///
14    /// - `fmt::Result` - Result of the formatting operation.
15    #[inline(always)]
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        match self {
18            Self::ZeroRate => f.write_str(ERR_ZERO_RATE),
19            Self::ZeroBurst => f.write_str(ERR_ZERO_BURST),
20            Self::ZeroPeriod => f.write_str(ERR_ZERO_PERIOD),
21            Self::InvalidLimit => f.write_str(ERR_INVALID_LIMIT),
22            Self::InvalidCapacity => f.write_str(ERR_INVALID_CAPACITY),
23            Self::ZeroCapacity => f.write_str(ERR_ZERO_CAPACITY),
24            Self::Overflow => f.write_str(ERR_OVERFLOW),
25        }
26    }
27}
28
29/// Marks `RateLimitError` as a standard error type.
30impl Error for RateLimitError {}