diff --git a/src/handshake/mod.rs b/src/handshake/mod.rs index 8546ca2..64d31f1 100644 --- a/src/handshake/mod.rs +++ b/src/handshake/mod.rs @@ -6,6 +6,8 @@ pub mod server; mod machine; +use std::error::Error as ErrorTrait; +use std::fmt; use std::io::{Read, Write}; use base64; @@ -62,6 +64,33 @@ pub enum HandshakeError { Failure(Error), } +impl fmt::Debug for HandshakeError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + HandshakeError::Interrupted(_) => write!(f, "HandshakeError::Interrupted(...)"), + HandshakeError::Failure(ref e) => write!(f, "HandshakeError::Failure({:?})", e), + } + } +} + +impl fmt::Display for HandshakeError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + HandshakeError::Interrupted(_) => write!(f, "Interrupted handshake (WouldBlock)"), + HandshakeError::Failure(ref e) => write!(f, "{}", e), + } + } +} + +impl ErrorTrait for HandshakeError { + fn description(&self) -> &str { + match *self { + HandshakeError::Interrupted(_) => "Interrupted handshake", + HandshakeError::Failure(ref e) => e.description(), + } + } +} + impl From for HandshakeError { fn from(err: Error) -> Self { HandshakeError::Failure(err)