From 3845f28dad3e94166dbcc4658f14e6465c558d5a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 16 May 2016 23:51:26 +0200 Subject: [PATCH] Implement IntoError for all generated Errors automatically --- libimagerror/src/error_gen.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libimagerror/src/error_gen.rs b/libimagerror/src/error_gen.rs index 2f22078a..f54334e4 100644 --- a/libimagerror/src/error_gen.rs +++ b/libimagerror/src/error_gen.rs @@ -1,3 +1,5 @@ +use into::IntoError; + #[macro_export] macro_rules! generate_error_imports { () => { @@ -41,6 +43,19 @@ macro_rules! generate_error_types { } + impl IntoError for $kindname { + type Target = $name; + + fn into_error(self) -> Self::Target { + $name::new(self, None) + } + + fn into_error_with_cause(self, cause: Box) -> Self::Target { + $name::new(self, Some(cause)) + } + + } + #[derive(Debug)] pub struct $name { err_type: $kindname,