network_communicator/
error.rs1use curl::Error as CurlError;
2use std::io::Error as IOError;
3use std::fmt::{Formatter,Debug,Display,Error as FormatterError};
4use std::error::Error as TraitError;
5use std::convert::From;
6
7pub enum Error<E> {
9 ThreadStartError { error: IOError },
11
12 Curl { error: CurlError },
15
16 EventLoop { description: String, debug_message: String },
20
21 Initialize { error: E },
23}
24
25impl <E> Debug for Error<E> {
26 #[allow(unused)]
27 fn fmt(&self, f: &mut Formatter) -> Result<(), FormatterError> {
28 match self {
29 &Error::ThreadStartError {ref error} => {
30 write!(f, "Unable to start thread: {:?}", error)
31 },
32 &Error::Curl {ref error} => {
33 write!(f, "Curl error: {:?}", error)
34 },
35 &Error::EventLoop {ref description,ref debug_message} => {
36 write!(f, "Event loop error: {}", debug_message)
37 },
38 &Error::Initialize {..} => {
39 write!(f, "Initialize error")
40 },
41 }
42 }
43}
44
45impl <E> Display for Error<E> {
46 fn fmt(&self, f: &mut Formatter) -> Result<(), FormatterError> {
47 write!(f,"{:?}",self)
48 }
49}
50
51impl <E>TraitError for Error<E> {
52 #[allow(unused)]
53 fn description(&self) -> &str {
54 match self {
55 &Error::ThreadStartError {..} => {
56 "Unable to start thread"
57 },
58 &Error::Curl {..} => {
59 "Curl error"
60 },
61 &Error::EventLoop {ref description,ref debug_message} => {
62 &description
63 },
64 &Error::Initialize {..} => {
65 "Initialize error"
66 },
67 }
68 }
69
70 fn cause(&self) -> Option<&TraitError> {
71 match self {
72 &Error::ThreadStartError {ref error} => {
73 Some(error)
74 },
75 &Error::Curl {ref error} => {
76 Some(error)
77 },
78 &Error::EventLoop {..} => {
79 None
80 },
81 &Error::Initialize {..} => {
82 None
83 },
84 }
85 }
86}
87
88
89impl <E>From<CurlError> for Error<E> {
90 fn from(error: CurlError) -> Self {
91 Error::Curl {
92 error: error
93 }
94 }
95}
96
97
98