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