Add Debug, Display and Error to HandshakeError

Signed-off-by: Alexey Galakhov <agalakhov@snapview.de>
pull/12/head
Alexey Galakhov 8 years ago
parent 0e8113e6e0
commit d29e3948d2
  1. 29
      src/handshake/mod.rs

@ -6,6 +6,8 @@ pub mod server;
mod machine; mod machine;
use std::error::Error as ErrorTrait;
use std::fmt;
use std::io::{Read, Write}; use std::io::{Read, Write};
use base64; use base64;
@ -62,6 +64,33 @@ pub enum HandshakeError<Stream, Role> {
Failure(Error), Failure(Error),
} }
impl<Stream, Role> fmt::Debug for HandshakeError<Stream, Role> {
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<Stream, Role> fmt::Display for HandshakeError<Stream, Role> {
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<Stream, Role> ErrorTrait for HandshakeError<Stream, Role> {
fn description(&self) -> &str {
match *self {
HandshakeError::Interrupted(_) => "Interrupted handshake",
HandshakeError::Failure(ref e) => e.description(),
}
}
}
impl<Stream, Role> From<Error> for HandshakeError<Stream, Role> { impl<Stream, Role> From<Error> for HandshakeError<Stream, Role> {
fn from(err: Error) -> Self { fn from(err: Error) -> Self {
HandshakeError::Failure(err) HandshakeError::Failure(err)

Loading…
Cancel
Save