@@ -42,7 +42,8 @@ macro_rules! impl_error_chain_processed {
42
42
}
43
43
44
44
links {
45
- $( $link_variant: ident ( $link_error_path: path, $link_kind_path: path )
45
+ $( $link_variant: ident ( $link_error_path: path, $link_kind_path: path,
46
+ $link_trait_path: path )
46
47
$( #[ $meta_links: meta] ) * ; ) *
47
48
}
48
49
@@ -70,7 +71,8 @@ macro_rules! impl_error_chain_processed {
70
71
/// internals, containing:
71
72
/// - a backtrace, generated when the error is created.
72
73
/// - an error chain, used for the implementation of `Error::cause()`.
73
- #[ derive( Debug , $( $derive) ,* ) ]
74
+ //#[derive(Debug, $($derive),*)]
75
+ #[ derive( Debug ) ]
74
76
pub struct $error_name(
75
77
// The members must be `pub` for `links`.
76
78
/// The kind of the error.
@@ -148,7 +150,7 @@ macro_rules! impl_error_chain_processed {
148
150
}
149
151
150
152
/// Construct a chained error from another boxed error and a kind, and generates a backtrace
151
- pub fn with_boxed_chain<K >( error: Box <:: std :: error :: Error + Send >, kind: K )
153
+ pub fn with_boxed_chain<K >( error: Box <Trait >, kind: K )
152
154
-> $error_name
153
155
where K : Into <$error_kind_name>
154
156
{
@@ -222,7 +224,7 @@ macro_rules! impl_error_chain_processed {
222
224
fn from( e: $link_error_path) -> Self {
223
225
$error_name(
224
226
$error_kind_name:: $link_variant( e. 0 ) ,
225
- e. 1 ,
227
+ :: State { next_error : e. 1 . next_error . map ( |e| $crate :: ConvertErrorTrait :: convert ( e ) ) , backtrace : e . 1 . backtrace } ,
226
228
)
227
229
}
228
230
}
@@ -332,7 +334,7 @@ macro_rules! impl_error_chain_processed {
332
334
EK : Into <$error_kind_name>;
333
335
}
334
336
335
- impl <T , E > $result_ext_name<T , E > for :: std:: result:: Result <T , E >
337
+ impl <T , E > $result_ext_name<T > for :: std:: result:: Result <T , E >
336
338
where E : Trait + ' static
337
339
{
338
340
fn chain_err<F , EK >( self , callback: F ) -> :: std:: result:: Result <T , $error_name>
@@ -354,8 +356,6 @@ macro_rules! impl_error_chain_processed {
354
356
} )
355
357
}
356
358
}
357
-
358
-
359
359
} ;
360
360
}
361
361
@@ -440,9 +440,21 @@ macro_rules! error_chain {
440
440
#[ doc( hidden) ]
441
441
macro_rules! create_super_trait {
442
442
( $name: ident: $bound_1: path, $( $rest: path) ,* ) => {
443
- trait $name: $bound_1 $( + $rest) * { }
443
+ pub trait $name: $bound_1 $( + $rest) * { }
444
444
impl <T : $bound_1 $( + $rest) * > $name for T { }
445
- } ;
445
+
446
+ pub trait ConvertErrorTrait {
447
+ type Target : ?Sized ;
448
+ fn convert( self : Box <Self >) -> Box <Self :: Target >;
449
+ }
450
+
451
+ impl <T : ?Sized + $bound_1 $( + $rest) * > ConvertErrorTrait for T {
452
+ type Target = Trait + ' static ;
453
+ fn convert( self : Box <Self >) -> Box <Self :: Target > {
454
+ Box :: new( self ) as Box <Trait >
455
+ }
456
+ }
457
+ } ;
446
458
}
447
459
448
460
/// Macro used to manage the `backtrace` feature.
0 commit comments