tower_resilience_cache/
error.rs1use std::fmt;
4
5#[derive(Debug)]
7pub enum CacheError<E> {
8 Inner(E),
10}
11
12impl<E: fmt::Display> fmt::Display for CacheError<E> {
13 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
14 match self {
15 CacheError::Inner(e) => write!(f, "inner service error: {}", e),
16 }
17 }
18}
19
20impl<E: std::error::Error + 'static> std::error::Error for CacheError<E> {
21 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
22 match self {
23 CacheError::Inner(e) => Some(e),
24 }
25 }
26}
27
28impl<E> CacheError<E> {
29 pub fn into_inner(self) -> E {
31 match self {
32 CacheError::Inner(e) => e,
33 }
34 }
35}
36
37#[derive(Debug)]
39pub enum CacheBuildError {
40 MissingKeyExtractor,
42}
43
44impl fmt::Display for CacheBuildError {
45 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
46 match self {
47 CacheBuildError::MissingKeyExtractor => {
48 write!(f, "key_extractor must be set before building")
49 }
50 }
51 }
52}
53
54impl std::error::Error for CacheBuildError {}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59
60 #[test]
61 fn test_inner_error() {
62 let err = CacheError::Inner("test error");
63 assert_eq!(err.to_string(), "inner service error: test error");
64 assert_eq!(err.into_inner(), "test error");
65 }
66}