1use std::fmt;
22use std::io;
23use std::error;
24
25pub mod constants;
26
27pub mod address;
28pub use self::address::Address;
29pub mod message;
30pub mod message_blockdata;
31pub mod message_network;
32pub mod message_filter;
33pub mod stream_reader;
34
35#[derive(Debug)]
37pub enum Error {
38 Io(io::Error),
40 SocketMutexPoisoned,
42 SocketNotConnectedToPeer,
44}
45
46impl fmt::Display for Error {
47 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48 match *self {
49 Error::Io(ref e) => fmt::Display::fmt(e, f),
50 Error::SocketMutexPoisoned => f.write_str("socket mutex was poisoned"),
51 Error::SocketNotConnectedToPeer => f.write_str("not connected to peer"),
52 }
53 }
54}
55
56#[doc(hidden)]
57impl From<io::Error> for Error {
58 fn from(err: io::Error) -> Self {
59 Error::Io(err)
60 }
61}
62
63impl error::Error for Error {
64
65 fn cause(&self) -> Option<&dyn error::Error> {
66 match *self {
67 Error::Io(ref e) => Some(e),
68 Error::SocketMutexPoisoned | Error::SocketNotConnectedToPeer => None,
69 }
70 }
71}