use std::io;
use thiserror::Error;
use crate::errors::{MspError, ProtocolError};
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum ConnectionError {
#[error("connection is closed")]
Closed,
#[error(transparent)]
Transport(#[from] io::Error),
#[error(transparent)]
Msp(#[from] MspError),
#[error(transparent)]
Protocol(#[from] ProtocolError),
}
impl Clone for ConnectionError {
fn clone(&self) -> Self {
match self {
Self::Closed => Self::Closed,
Self::Transport(error) => {
Self::Transport(io::Error::new(error.kind(), error.to_string()))
}
Self::Msp(error) => Self::Msp(error.clone()),
Self::Protocol(error) => Self::Protocol(error.clone()),
}
}
}
impl PartialEq for ConnectionError {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Closed, Self::Closed) => true,
(Self::Transport(left), Self::Transport(right)) => left.kind() == right.kind(),
(Self::Msp(left), Self::Msp(right)) => left == right,
(Self::Protocol(left), Self::Protocol(right)) => left == right,
_ => false,
}
}
}