r_token/models/rtoken_error.rs
1//! Error types for r-token.
2//!
3//! The library intentionally keeps its own error type small. It is primarily used
4//! by [`crate::RTokenManager`] methods and can also be returned from actix-web handlers
5//! because it implements `actix_web::ResponseError`.
6//!
7//! ## 繁體中文
8//!
9//! r-token 的錯誤型別。
10//!
11//! 本庫的錯誤型別刻意保持精簡,主要由 [`crate::RTokenManager`] 方法回傳。
12//! 因為實作了 `actix_web::ResponseError`,也可以直接作為 actix-web handler 的錯誤型別使用。
13
14use std::fmt::Formatter;
15
16/// Errors returned by r-token.
17///
18/// ## 繁體中文
19///
20/// r-token 會回傳的錯誤集合。
21#[derive(Debug)]
22pub enum RTokenError {
23 /// The internal mutex has been poisoned.
24 ///
25 /// ## 繁體中文
26 ///
27 /// 內部 mutex 發生 poisoned。
28 MutexPoisoned,
29}
30
31impl std::fmt::Display for RTokenError {
32 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
33 match self {
34 RTokenError::MutexPoisoned => write!(f, "Token manager mutex poisoned"),
35 }
36 }
37}
38
39impl std::error::Error for RTokenError {}
40
41#[cfg(feature = "actix")]
42impl actix_web::ResponseError for RTokenError {}