use super::Error;
#[derive(Debug)]
pub(super) struct ConnectionLost {
pub(super) inner: Box<dyn std::error::Error + Send + Sync>,
}
impl std::error::Error for ConnectionLost {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
Some(self.inner.as_ref())
}
}
impl core::fmt::Display for ConnectionLost {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
write!(f, "connection lost: ")?;
core::fmt::Display::fmt(&self.inner, f)?;
let mut source = self.inner.source();
while let Some(err) = source {
write!(f, ": {}", err)?;
source = err.source();
}
Ok(())
}
}
impl Error {
pub fn connection_lost(err: impl std::error::Error + Send + Sync + 'static) -> Error {
Error::from(super::ErrorKind::ConnectionLost(ConnectionLost {
inner: Box::new(err),
}))
}
pub fn is_connection_lost(&self) -> bool {
matches!(self.kind(), super::ErrorKind::ConnectionLost(_))
}
}