@@ -54,10 +54,10 @@ macro_rules! error_chain_processed {
5454 }
5555
5656 derive {
57- $( $bound : ident) , *
57+ $( $derive : ident, $bound : path ) ; *
5858 }
5959 ) => {
60- create_super_trait!( Trait : :: std:: fmt:: Debug , :: std:: error:: Error , Send $( , $bound) * ) ;
60+ create_super_trait!( Trait : :: std:: fmt:: Debug , :: std:: error:: Error , $crate :: ToError , Send $( , $bound) * ) ;
6161
6262 /// The Error type.
6363 ///
@@ -68,7 +68,7 @@ macro_rules! error_chain_processed {
6868 /// internals, containing:
6969 /// - a backtrace, generated when the error is created.
7070 /// - an error chain, used for the implementation of `Error::cause()`.
71- #[ derive( Debug , $( $bound ) ,* ) ]
71+ #[ derive( Debug , $( $derive ) ,* ) ]
7272 pub struct $error_name(
7373 // The members must be `pub` for `links`.
7474 /// The kind of the error.
@@ -78,6 +78,12 @@ macro_rules! error_chain_processed {
7878 pub $crate:: State <Trait >,
7979 ) ;
8080
81+ impl $crate:: ToError for $error_name {
82+ fn to_error( & self ) -> & ( :: std:: error:: Error + Send + ' static ) {
83+ self
84+ }
85+ }
86+
8187 impl $crate:: ChainedError <Trait > for $error_name {
8288 type ErrorKind = $error_kind_name;
8389
@@ -91,7 +97,7 @@ macro_rules! error_chain_processed {
9197
9298 fn with_chain<E , K >( error: E , kind: K )
9399 -> Self
94- where E : :: std:: error:: Error + Send + ' static ,
100+ where E : $crate :: ToError + :: std:: error:: Error + Send + ' static ,
95101 K : Into <Self :: ErrorKind >
96102 {
97103 Self :: with_chain( error, kind)
@@ -133,12 +139,12 @@ macro_rules! error_chain_processed {
133139 /// Constructs a chained error from another error and a kind, and generates a backtrace.
134140 pub fn with_chain<E , K >( error: E , kind: K )
135141 -> $error_name
136- where E : :: std :: error :: Error + Send + ' static ,
142+ where E : Trait + ' static ,
137143 K : Into <$error_kind_name>
138144 {
139145 $error_name(
140146 kind. into( ) ,
141- $crate:: State :: new:: <$error_name>( Box :: new( error) , ) ,
147+ $crate:: State :: new:: <$error_name>( Box :: new( error) ) ,
142148 )
143149 }
144150
@@ -171,7 +177,7 @@ macro_rules! error_chain_processed {
171177
172178 fn cause( & self ) -> Option <& :: std:: error:: Error > {
173179 match self . 1 . next_error {
174- Some ( ref c) => Some ( & * * c ) ,
180+ Some ( ref c) => Some ( c . to_error ( ) ) ,
175181 None => {
176182 match self . 0 {
177183 $(
@@ -248,7 +254,7 @@ macro_rules! error_chain_processed {
248254
249255 quick_error! {
250256 /// The kind of an error.
251- #[ derive( Debug , $( $bound ) ,* ) ]
257+ #[ derive( Debug , $( $derive ) ,* ) ]
252258 pub enum $error_kind_name {
253259
254260 /// A convenient variant for String.
@@ -317,12 +323,14 @@ macro_rules! error_chain_processed {
317323 EK : Into <$error_kind_name>;
318324 }
319325
320- impl <T , E > $result_ext_name<T , E > for :: std:: result:: Result <T , E > where E : :: std:: error:: Error + Send + ' static {
326+ impl <T , E > $result_ext_name<T , E > for :: std:: result:: Result <T , E >
327+ where E : Trait + ' static
328+ {
321329 fn chain_err<F , EK >( self , callback: F ) -> :: std:: result:: Result <T , $error_name>
322330 where F : FnOnce ( ) -> EK ,
323331 EK : Into <$error_kind_name> {
324332 self . map_err( move |e| {
325- let state = $crate:: State :: new:: <$error_name>( Box :: new( e) , ) ;
333+ let state = $crate:: State :: new:: <$error_name>( Box :: new( e) ) ;
326334 $crate:: ChainedError :: new( callback( ) . into( ) , state)
327335 } )
328336 }
0 commit comments