1use std::error::Error as StdError;
4use std::fmt;
5
6const CLAIM_FAILURE_STR: &str = "Unable to retrieve a connection within the \
7 claim timeout";
8const BACKEND_NO_CONNECTION_STR: &str = "Found a backend key with no \
9 associated connection";
10const CONNECTION_RETRIEVAL_FAILURE_STR: &str = "Unable to retrieve a \
11 connection";
12const STOP_CALLED_BY_CLONE_STR: &str =
13 "ConnectionPool clones may not stop the \
14 connection pool.";
15const DUMMY_ERROR_STR: &str = "dummy error";
16
17#[derive(Debug)]
18pub enum Error {
21 ClaimFailure,
23 StopCalledByClone,
28 BackendWithNoConnection,
32 ConnectionRetrievalFailure,
37 #[doc(hidden)]
39 DummyError,
40}
41
42impl fmt::Display for Error {
43 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
44 match self {
45 Error::ClaimFailure => CLAIM_FAILURE_STR.fmt(fmt),
46 Error::BackendWithNoConnection => {
47 BACKEND_NO_CONNECTION_STR.fmt(fmt)
48 }
49 Error::ConnectionRetrievalFailure => {
50 CONNECTION_RETRIEVAL_FAILURE_STR.fmt(fmt)
51 }
52 Error::StopCalledByClone => STOP_CALLED_BY_CLONE_STR.fmt(fmt),
53 Error::DummyError => DUMMY_ERROR_STR.fmt(fmt),
54 }
55 }
56}
57
58impl StdError for Error {
59 fn description(&self) -> &str {
60 match self {
61 Error::ClaimFailure => CLAIM_FAILURE_STR,
62 Error::BackendWithNoConnection => BACKEND_NO_CONNECTION_STR,
63 Error::ConnectionRetrievalFailure => {
64 CONNECTION_RETRIEVAL_FAILURE_STR
65 }
66 Error::StopCalledByClone => STOP_CALLED_BY_CLONE_STR,
67 Error::DummyError => DUMMY_ERROR_STR,
68 }
69 }
70
71 fn source(&self) -> Option<&(dyn StdError + 'static)> {
72 None
73 }
74}