toasty_core/error/
connection_pool.rs

1use super::Error;
2
3/// Error from a connection pool.
4#[derive(Debug)]
5pub(super) struct ConnectionPool {
6    pub(super) inner: Box<dyn std::error::Error + Send + Sync>,
7}
8
9impl std::error::Error for ConnectionPool {
10    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
11        Some(self.inner.as_ref())
12    }
13}
14
15impl core::fmt::Display for ConnectionPool {
16    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
17        // Display the error and walk its source chain
18        core::fmt::Display::fmt(&self.inner, f)?;
19        let mut source = self.inner.source();
20        while let Some(err) = source {
21            write!(f, ": {}", err)?;
22            source = err.source();
23        }
24        Ok(())
25    }
26}
27
28impl Error {
29    /// Creates an error from a connection pool error.
30    ///
31    /// This is used for errors that occur when managing the connection pool (e.g., deadpool errors).
32    pub fn connection_pool(err: impl std::error::Error + Send + Sync + 'static) -> Error {
33        Error::from(super::ErrorKind::ConnectionPool(ConnectionPool {
34            inner: Box::new(err),
35        }))
36    }
37
38    /// Returns `true` if this error is a connection pool error.
39    pub fn is_connection_pool(&self) -> bool {
40        matches!(self.kind(), super::ErrorKind::ConnectionPool(_))
41    }
42}