diff options
author | khai96_ <hvksmr1996@gmail.com> | 2019-04-27 06:56:45 +0000 |
---|---|---|
committer | khai96_ <hvksmr1996@gmail.com> | 2019-04-27 06:56:45 +0000 |
commit | 58eee2f329859c33008a5b8b5af53189b2b4ab4a (patch) | |
tree | 2aa131c47eec383ca9dea843c735a05688fd7421 /src/errors.rs | |
parent | Merge pull request #84 from KSXGitHub/patch-1 (diff) | |
download | miniserve-58eee2f329859c33008a5b8b5af53189b2b4ab4a.tar.gz miniserve-58eee2f329859c33008a5b8b5af53189b2b4ab4a.zip |
Combine ContextualError and ContextualErrorKind into one
Diffstat (limited to 'src/errors.rs')
-rw-r--r-- | src/errors.rs | 58 |
1 files changed, 4 insertions, 54 deletions
diff --git a/src/errors.rs b/src/errors.rs index 833e9c4..b8af25d 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,8 +1,7 @@ -use failure::{Backtrace, Context, Fail}; -use std::fmt::{self, Debug, Display}; +use failure::Fail; #[derive(Debug, Fail)] -pub enum ContextualErrorKind { +pub enum ContextualError { /// Fully customized errors, not inheriting from any error #[fail(display = "{}", _0)] CustomError(String), @@ -73,58 +72,9 @@ pub fn log_error_chain(description: String) { } } -/// Based on https://boats.gitlab.io/failure/error-errorkind.html -pub struct ContextualError { - inner: Context<ContextualErrorKind>, -} - -impl ContextualError { - pub fn new(kind: ContextualErrorKind) -> ContextualError { - ContextualError { - inner: Context::new(kind), - } - } -} - -impl Fail for ContextualError { - fn cause(&self) -> Option<&Fail> { - self.inner.cause() - } - - fn backtrace(&self) -> Option<&Backtrace> { - self.inner.backtrace() - } -} - -impl Display for ContextualError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Display::fmt(&self.inner, f) - } -} - -impl Debug for ContextualError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - Debug::fmt(&self.inner, f) - } -} - -impl From<Context<ContextualErrorKind>> for ContextualError { - fn from(inner: Context<ContextualErrorKind>) -> ContextualError { - ContextualError { inner } - } -} - -impl From<ContextualErrorKind> for ContextualError { - fn from(kind: ContextualErrorKind) -> ContextualError { - ContextualError { - inner: Context::new(kind), - } - } -} - -/// This allows to create CustomErrors more simply +/// This makes creating CustomErrors easier impl From<String> for ContextualError { fn from(msg: String) -> ContextualError { - ContextualError::new(ContextualErrorKind::CustomError(msg)) + ContextualError::CustomError(msg) } } |