1use std::fmt;
11
12#[derive(Debug)]
13pub enum Error {
14 ClientError(String),
15 RemoteEndpointError(String),
16 GeneralError(String),
17}
18
19impl From<std::io::Error> for Error {
20 fn from(error: std::io::Error) -> Self {
21 Error::GeneralError(error.to_string())
22 }
23}
24
25pub type Result<T> = std::result::Result<T, Error>;
26
27impl From<Error> for String {
28 fn from(error: Error) -> String {
29 error.to_string()
30 }
31}
32
33impl fmt::Display for Error {
34 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
35 use Error::*;
36
37 let (error_type, error_msg) = match self {
38 ClientError(info) => ("ClientError", info),
39 RemoteEndpointError(info) => ("RemoteEndpointError", info),
40 GeneralError(info) => ("GeneralError", info),
41 };
42 let description = format!("[Error] {} - {}", error_type, error_msg);
43
44 write!(f, "{}", description)
45 }
46}