mqtt_packet/
error.rs

1use std::error::Error as StdError;
2use std::fmt;
3use std::io::Error as IoError;
4use std::num::TryFromIntError;
5use std::string::FromUtf8Error;
6
7/// Error type used in all `Result<T, E>` return values.
8#[derive(Debug, PartialEq, Eq)]
9pub enum Error {
10  ParseError,
11  GenerateError,
12}
13
14impl StdError for Error {
15  fn description(&self) -> &str {
16    match *self {
17      Error::ParseError => "Unable to parse type",
18      Error::GenerateError => "Unable to generate data",
19    }
20  }
21}
22
23impl fmt::Display for Error {
24  fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25    match *self {
26      Error::ParseError => f.write_str("ParseError"),
27      Error::GenerateError => f.write_str("GenerateError"),
28    }
29  }
30}
31
32impl From<IoError> for Error {
33  fn from(e: IoError) -> Self {
34    match e {
35      _ => Error::ParseError,
36    }
37  }
38}
39
40impl From<FromUtf8Error> for Error {
41  fn from(e: FromUtf8Error) -> Self {
42    match e {
43      _ => Error::ParseError,
44    }
45  }
46}
47
48impl From<TryFromIntError> for Error {
49  fn from(e: TryFromIntError) -> Self {
50    match e {
51      _ => Error::ParseError,
52    }
53  }
54}