@@ -54,10 +54,10 @@ macro_rules! error_chain_processed {
54
54
}
55
55
56
56
derive {
57
- $( $bound : ident) , *
57
+ $( $derive : ident, $bound : path ) ; *
58
58
}
59
59
) => {
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) * ) ;
61
61
62
62
/// The Error type.
63
63
///
@@ -68,7 +68,7 @@ macro_rules! error_chain_processed {
68
68
/// internals, containing:
69
69
/// - a backtrace, generated when the error is created.
70
70
/// - an error chain, used for the implementation of `Error::cause()`.
71
- #[ derive( Debug , $( $bound ) ,* ) ]
71
+ #[ derive( Debug , $( $derive ) ,* ) ]
72
72
pub struct $error_name(
73
73
// The members must be `pub` for `links`.
74
74
/// The kind of the error.
@@ -78,6 +78,12 @@ macro_rules! error_chain_processed {
78
78
pub $crate:: State <Trait >,
79
79
) ;
80
80
81
+ impl $crate:: ToError for $error_name {
82
+ fn to_error( & self ) -> & ( :: std:: error:: Error + Send + ' static ) {
83
+ self
84
+ }
85
+ }
86
+
81
87
impl $crate:: ChainedError <Trait > for $error_name {
82
88
type ErrorKind = $error_kind_name;
83
89
@@ -91,7 +97,7 @@ macro_rules! error_chain_processed {
91
97
92
98
fn with_chain<E , K >( error: E , kind: K )
93
99
-> Self
94
- where E : :: std:: error:: Error + Send + ' static ,
100
+ where E : $crate :: ToError + :: std:: error:: Error + Send + ' static ,
95
101
K : Into <Self :: ErrorKind >
96
102
{
97
103
Self :: with_chain( error, kind)
@@ -133,7 +139,7 @@ macro_rules! error_chain_processed {
133
139
/// Constructs a chained error from another error and a kind, and generates a backtrace.
134
140
pub fn with_chain<E , K >( error: E , kind: K )
135
141
-> $error_name
136
- where E : :: std :: error :: Error + Send + ' static ,
142
+ where E : Trait + ' static ,
137
143
K : Into <$error_kind_name>
138
144
{
139
145
$error_name:: with_boxed_chain( Box :: new( error) , kind)
@@ -180,7 +186,7 @@ macro_rules! error_chain_processed {
180
186
#[ allow( unknown_lints, unused_doc_comment) ]
181
187
fn cause( & self ) -> Option <& :: std:: error:: Error > {
182
188
match self . 1 . next_error {
183
- Some ( ref c) => Some ( & * * c ) ,
189
+ Some ( ref c) => Some ( c . to_error ( ) ) ,
184
190
None => {
185
191
match self . 0 {
186
192
$(
@@ -257,7 +263,7 @@ macro_rules! error_chain_processed {
257
263
258
264
quick_error! {
259
265
/// The kind of an error.
260
- #[ derive( Debug , $( $bound ) ,* ) ]
266
+ #[ derive( Debug , $( $derive ) ,* ) ]
261
267
pub enum $error_kind_name {
262
268
263
269
/// A convenient variant for String.
@@ -326,12 +332,18 @@ macro_rules! error_chain_processed {
326
332
EK : Into <$error_kind_name>;
327
333
}
328
334
335
+ <<<<<<< HEAD
329
336
impl <T , E > $result_ext_name<T > for :: std:: result:: Result <T , E > where E : :: std:: error:: Error + Send + ' static {
337
+ =======
338
+ impl <T , E > $result_ext_name<T , E > for :: std:: result:: Result <T , E >
339
+ where E : Trait + ' static
340
+ {
341
+ >>>>>>> Change `derive` block to take the derive macro name and path to the trait
330
342
fn chain_err<F , EK >( self , callback: F ) -> :: std:: result:: Result <T , $error_name>
331
343
where F : FnOnce ( ) -> EK ,
332
344
EK : Into <$error_kind_name> {
333
345
self . map_err( move |e| {
334
- let state = $crate:: State :: new:: <$error_name>( Box :: new( e) , ) ;
346
+ let state = $crate:: State :: new:: <$error_name>( Box :: new( e) ) ;
335
347
$crate:: ChainedError :: new( callback( ) . into( ) , state)
336
348
} )
337
349
}
0 commit comments