From 8e0014d5079fc1b5d0036965b8fa452038a79e11 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 16 May 2016 23:51:13 +0200 Subject: [PATCH] Add IntoError trait to convert Error kinds into Error instances --- libimagerror/src/into.rs | 14 ++++++++++++++ libimagerror/src/lib.rs | 1 + 2 files changed, 15 insertions(+) create mode 100644 libimagerror/src/into.rs diff --git a/libimagerror/src/into.rs b/libimagerror/src/into.rs new file mode 100644 index 00000000..a959abd4 --- /dev/null +++ b/libimagerror/src/into.rs @@ -0,0 +1,14 @@ +use std::error::Error; + +/// Trait to help converting Error kinds into Error instances +pub trait IntoError { + type Target: Error; + + /// Convert the type into an error with no cause + fn into_error(self) -> Self::Target; + + /// Convert the type into an error with cause + fn into_error_with_cause(self, cause: Box) -> Self::Target; + +} + diff --git a/libimagerror/src/lib.rs b/libimagerror/src/lib.rs index d7f374a7..1d1f75e2 100644 --- a/libimagerror/src/lib.rs +++ b/libimagerror/src/lib.rs @@ -1,5 +1,6 @@ #[macro_use] extern crate log; extern crate ansi_term; +pub mod into; pub mod error_gen; pub mod trace;