actix_rl/
error.rs

1use std::fmt::{Display, Formatter};
2use chrono::{DateTime, Utc};
3
4#[derive(Debug, Clone, Copy, Eq, PartialEq)]
5pub enum Error {
6    /// [Self::RateLimited] indicates that the limit has been reached
7    /// and returns the time when the limit will be lifted.
8    RateLimited(Option<DateTime<Utc>>),
9}
10
11impl Display for Error {
12    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
13        match *self {
14            Self::RateLimited(until) => if let Some(until) = until {
15                write!(f, "rate limited, until {}", until.timestamp())
16            } else {
17                write!(f, "rate limited")
18            }
19        }
20    }
21}
22
23impl std::error::Error for Error {}