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