muse_code_sdk/connection/
error.rs1use std::io;
2
3use thiserror::Error;
4
5use crate::errors::{MspError, ProtocolError};
6
7#[derive(Debug, Error)]
9#[non_exhaustive]
10pub enum ConnectionError {
11 #[error("connection is closed")]
13 Closed,
14 #[error(transparent)]
16 Transport(#[from] io::Error),
17 #[error(transparent)]
19 Msp(#[from] MspError),
20 #[error(transparent)]
23 Protocol(#[from] ProtocolError),
24}
25
26impl Clone for ConnectionError {
27 fn clone(&self) -> Self {
28 match self {
29 Self::Closed => Self::Closed,
30 Self::Transport(error) => {
33 Self::Transport(io::Error::new(error.kind(), error.to_string()))
34 }
35 Self::Msp(error) => Self::Msp(error.clone()),
36 Self::Protocol(error) => Self::Protocol(error.clone()),
37 }
38 }
39}
40
41impl PartialEq for ConnectionError {
42 fn eq(&self, other: &Self) -> bool {
43 match (self, other) {
44 (Self::Closed, Self::Closed) => true,
45 (Self::Transport(left), Self::Transport(right)) => left.kind() == right.kind(),
46 (Self::Msp(left), Self::Msp(right)) => left == right,
47 (Self::Protocol(left), Self::Protocol(right)) => left == right,
48 _ => false,
49 }
50 }
51}