1use std::fmt::{Display, Formatter};
2use std::io::Error as IoError;
3use std::{convert, error};
4#[cfg(feature = "ssl")]
5use webpki::InvalidDNSNameError;
6
7pub type IgniteResult<T> = Result<T, IgniteError>;
8
9#[derive(Debug)]
10pub struct IgniteError {
11 pub(crate) desc: String,
12}
13
14impl error::Error for IgniteError {}
15
16impl Display for IgniteError {
17 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
18 write!(f, "{}", self.desc)
19 }
20}
21
22impl convert::From<IoError> for IgniteError {
23 fn from(e: IoError) -> Self {
24 IgniteError {
25 desc: e.to_string(),
26 }
27 }
28}
29
30impl convert::From<&str> for IgniteError {
31 fn from(desc: &str) -> Self {
32 IgniteError {
33 desc: String::from(desc),
34 }
35 }
36}
37
38impl convert::From<Option<String>> for IgniteError {
39 fn from(desc: Option<String>) -> Self {
40 match desc {
41 Some(desc) => IgniteError { desc },
42 None => IgniteError {
43 desc: "Ignite client error! No description provided".to_owned(),
44 },
45 }
46 }
47}
48
49#[cfg(feature = "ssl")]
50impl convert::From<InvalidDNSNameError> for IgniteError {
51 fn from(err: InvalidDNSNameError) -> Self {
52 IgniteError {
53 desc: err.to_string(),
54 }
55 }
56}