@@ -56,10 +56,10 @@ macro_rules! impl_error_chain_processed {
5656 }
5757
5858 derive {
59- $( $bound : ident) , *
59+ $( $derive : ident, $bound : path ) ; *
6060 }
6161 ) => {
62- create_super_trait!( Trait : :: std:: fmt:: Debug , :: std:: error:: Error , Send $( , $bound) * ) ;
62+ create_super_trait!( Trait : :: std:: fmt:: Debug , :: std:: error:: Error , $crate :: ToError , Send $( , $bound) * ) ;
6363
6464 /// The Error type.
6565 ///
@@ -70,7 +70,7 @@ macro_rules! impl_error_chain_processed {
7070 /// internals, containing:
7171 /// - a backtrace, generated when the error is created.
7272 /// - an error chain, used for the implementation of `Error::cause()`.
73- #[ derive( Debug , $( $bound ) ,* ) ]
73+ #[ derive( Debug , $( $derive ) ,* ) ]
7474 pub struct $error_name(
7575 // The members must be `pub` for `links`.
7676 /// The kind of the error.
@@ -80,6 +80,12 @@ macro_rules! impl_error_chain_processed {
8080 pub $crate:: State <Trait >,
8181 ) ;
8282
83+ impl $crate:: ToError for $error_name {
84+ fn to_error( & self ) -> & ( :: std:: error:: Error + Send + ' static ) {
85+ self
86+ }
87+ }
88+
8389 impl $crate:: ChainedError <Trait > for $error_name {
8490 type ErrorKind = $error_kind_name;
8591
@@ -93,7 +99,7 @@ macro_rules! impl_error_chain_processed {
9399
94100 fn with_chain<E , K >( error: E , kind: K )
95101 -> Self
96- where E : :: std:: error:: Error + Send + ' static ,
102+ where E : $crate :: ToError + :: std:: error:: Error + Send + ' static ,
97103 K : Into <Self :: ErrorKind >
98104 {
99105 Self :: with_chain( error, kind)
@@ -135,7 +141,7 @@ macro_rules! impl_error_chain_processed {
135141 /// Constructs a chained error from another error and a kind, and generates a backtrace.
136142 pub fn with_chain<E , K >( error: E , kind: K )
137143 -> $error_name
138- where E : :: std :: error :: Error + Send + ' static ,
144+ where E : Trait + ' static ,
139145 K : Into <$error_kind_name>
140146 {
141147 $error_name:: with_boxed_chain( Box :: new( error) , kind)
@@ -188,7 +194,7 @@ macro_rules! impl_error_chain_processed {
188194 #[ allow( unknown_lints, unused_doc_comment) ]
189195 fn cause( & self ) -> Option <& :: std:: error:: Error > {
190196 match self . 1 . next_error {
191- Some ( ref c) => Some ( & * * c ) ,
197+ Some ( ref c) => Some ( c . to_error ( ) ) ,
192198 None => {
193199 match self . 0 {
194200 $(
@@ -257,7 +263,7 @@ macro_rules! impl_error_chain_processed {
257263
258264 impl_error_chain_kind! {
259265 /// The kind of an error.
260- #[ derive( Debug , $( $bound ) ,* ) ]
266+ #[ derive( Debug , $( $derive ) ,* ) ]
261267 pub enum $error_kind_name {
262268
263269 /// A convenient variant for String.
@@ -326,12 +332,14 @@ macro_rules! impl_error_chain_processed {
326332 EK : Into <$error_kind_name>;
327333 }
328334
329- impl <T , E > $result_ext_name<T > for :: std:: result:: Result <T , E > where E : :: std:: error:: Error + Send + ' static {
335+ impl <T , E > $result_ext_name<T , E > for :: std:: result:: Result <T , E >
336+ where E : Trait + ' static
337+ {
330338 fn chain_err<F , EK >( self , callback: F ) -> :: std:: result:: Result <T , $error_name>
331339 where F : FnOnce ( ) -> EK ,
332340 EK : Into <$error_kind_name> {
333341 self . map_err( move |e| {
334- let state = $crate:: State :: new:: <$error_name>( Box :: new( e) , ) ;
342+ let state = $crate:: State :: new:: <$error_name>( Box :: new( e) ) ;
335343 $crate:: ChainedError :: new( callback( ) . into( ) , state)
336344 } )
337345 }
0 commit comments