1use std::fmt;
18use std::fmt::{Display, Formatter};
19use std::io::Error;
20use std::string::FromUtf8Error;
21
22#[derive(Debug)]
23pub enum RigCtlError {
24 ConnectionError(String),
25 AlreadyConnected,
26 RawDataError(String),
27 ResponseParsing(String),
28 CommunicationTimeout,
29}
30
31impl Display for RigCtlError {
32 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
33 match self {
34 RigCtlError::ConnectionError(message) => { write!(f, "Connection error: {}", message) }
35 RigCtlError::AlreadyConnected => { write!(f, "Already connected") }
36 RigCtlError::RawDataError(message) => { write!(f, "Raw data error: {}", message) }
37 RigCtlError::ResponseParsing(message) => { write!(f, "Response parsing error: {}", message) }
38 RigCtlError::CommunicationTimeout => { write!(f, "Communication timeout") }
39 }
40 }
41}
42
43impl From<Error> for RigCtlError {
44 fn from(value: Error) -> Self {
45 RigCtlError::ConnectionError(value.to_string())
46 }
47}
48
49impl From<FromUtf8Error> for RigCtlError {
50 fn from(value: FromUtf8Error) -> Self {
51 RigCtlError::RawDataError(value.to_string())
52 }
53}