bluerobotics_ping/
error.rs

1use crate::{decoder, message::ProtocolMessage};
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone)]
6#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
7pub enum PingError {
8    Io(String),
9    ParseError(decoder::ParseError),
10    TokioBroadcastError(String),
11    TokioMpscError(String),
12    JoinError,
13    TimeoutError,
14    TryFromError(ProtocolMessage),
15    NackError(String),
16}
17
18impl From<std::io::Error> for PingError {
19    fn from(err: std::io::Error) -> PingError {
20        PingError::Io(err.to_string())
21    }
22}
23
24impl From<tokio::sync::mpsc::error::SendError<ProtocolMessage>> for PingError {
25    fn from(err: tokio::sync::mpsc::error::SendError<ProtocolMessage>) -> PingError {
26        PingError::TokioMpscError(err.to_string())
27    }
28}
29
30impl From<tokio::sync::broadcast::error::RecvError> for PingError {
31    fn from(err: tokio::sync::broadcast::error::RecvError) -> PingError {
32        PingError::TokioBroadcastError(err.to_string())
33    }
34}