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
use crate::{decoder, message::ProtocolMessage};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum PingError {
    Io(String),
    ParseError(decoder::ParseError),
    TokioBroadcastError(String),
    TokioMpscError(String),
    JoinError,
    TimeoutError,
    TryFromError(ProtocolMessage),
    NackError(String),
}

impl From<std::io::Error> for PingError {
    fn from(err: std::io::Error) -> PingError {
        PingError::Io(err.to_string())
    }
}

impl From<tokio::sync::mpsc::error::SendError<ProtocolMessage>> for PingError {
    fn from(err: tokio::sync::mpsc::error::SendError<ProtocolMessage>) -> PingError {
        PingError::TokioMpscError(err.to_string())
    }
}

impl From<tokio::sync::broadcast::error::RecvError> for PingError {
    fn from(err: tokio::sync::broadcast::error::RecvError) -> PingError {
        PingError::TokioBroadcastError(err.to_string())
    }
}