diff options
| author | Steven Fackler <[email protected]> | 2014-11-16 22:21:45 -0800 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2014-11-16 22:21:45 -0800 |
| commit | 2569b398556dcec70ba2dc4369327172bedef375 (patch) | |
| tree | c762efea9d0854d979671176d0f6d3c57aaebe6b /src | |
| parent | Fix travis features (diff) | |
| download | rust-openssl-2569b398556dcec70ba2dc4369327172bedef375.tar.xz rust-openssl-2569b398556dcec70ba2dc4369327172bedef375.zip | |
Impl Error for SslError
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib.rs | 2 | ||||
| -rw-r--r-- | src/ssl/error.rs | 23 |
2 files changed, 23 insertions, 2 deletions
@@ -1,4 +1,4 @@ -#![feature(struct_variant, macro_rules, unsafe_destructor)] +#![feature(struct_variant, macro_rules, unsafe_destructor, globs)] #![crate_name="openssl"] #![crate_type="rlib"] #![crate_type="dylib"] diff --git a/src/ssl/error.rs b/src/ssl/error.rs index 7066299f..7e8daef1 100644 --- a/src/ssl/error.rs +++ b/src/ssl/error.rs @@ -1,4 +1,8 @@ +pub use self::SslError::*; +pub use self::OpensslError::*; + use libc::c_ulong; +use std::error; use std::io::IoError; use std::c_str::CString; @@ -7,7 +11,7 @@ use ffi; /// An SSL error #[deriving(Show, Clone, PartialEq, Eq)] pub enum SslError { - /// The underlying stream has reported an error + /// The underlying stream reported an error StreamError(IoError), /// The SSL session has been closed by the other end SslSessionClosed, @@ -15,6 +19,23 @@ pub enum SslError { OpenSslErrors(Vec<OpensslError>) } +impl error::Error for SslError { + fn description(&self) -> &str { + match *self { + StreamError(_) => "The underlying stream reported an error", + SslSessionClosed => "The SSL session has been closed by the other end", + OpenSslErrors(_) => "An error in the OpenSSL library", + } + } + + fn cause(&self) -> Option<&error::Error> { + match *self { + StreamError(ref err) => Some(err as &error::Error), + _ => None + } + } +} + /// An error from the OpenSSL library #[deriving(Show, Clone, PartialEq, Eq)] pub enum OpensslError { |