queen_core/wire_protocol/
error.rs1use std::io;
2use std::result;
3use std::fmt;
4use std::error;
5use std::string;
6
7pub type Result<T> = result::Result<T, Error>;
8
9#[derive(Debug)]
10pub enum Error {
11 IoError(io::Error),
12 ResponseError(String),
13 FromUtf8Error(string::FromUtf8Error),
14}
15
16impl<'a> From<Error> for io::Error {
17 fn from(err: Error) -> io::Error {
18 io::Error::new(io::ErrorKind::Other, err)
19 }
20}
21
22impl From<io::Error> for Error {
23 fn from(err: io::Error) -> Error {
24 Error::IoError(err)
25 }
26}
27
28impl From<string::FromUtf8Error> for Error {
29 fn from(err: string::FromUtf8Error) -> Error {
30 Error::FromUtf8Error(err)
31 }
32}
33
34impl fmt::Display for Error {
35 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
36 match *self {
37 Error::IoError(ref inner) => inner.fmt(fmt),
38 Error::ResponseError(ref inner) => inner.fmt(fmt),
39 Error::FromUtf8Error(ref inner) => inner.fmt(fmt)
40 }
41 }
42}
43
44impl error::Error for Error {
45 fn description(&self) -> &str {
46 match *self {
47 Error::IoError(ref inner) => inner.description(),
48 Error::ResponseError(ref inner) => inner,
49 Error::FromUtf8Error(ref inner) => inner.description()
50 }
51 }
52
53 fn cause(&self) -> Option<&error::Error> {
54 match *self {
55 Error::IoError(ref inner) => Some(inner),
56 Error::ResponseError(_) => None,
57 Error::FromUtf8Error(ref inner) => Some(inner)
58 }
59 }
60}