@@ -56,10 +56,10 @@ macro_rules! impl_error_chain_processed {
56
56
}
57
57
58
58
derive {
59
- $( $bound : ident) , *
59
+ $( $derive : ident, $bound : path ) ; *
60
60
}
61
61
) => {
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) * ) ;
63
63
64
64
/// The Error type.
65
65
///
@@ -70,7 +70,7 @@ macro_rules! impl_error_chain_processed {
70
70
/// internals, containing:
71
71
/// - a backtrace, generated when the error is created.
72
72
/// - an error chain, used for the implementation of `Error::cause()`.
73
- #[ derive( Debug , $( $bound ) ,* ) ]
73
+ #[ derive( Debug , $( $derive ) ,* ) ]
74
74
pub struct $error_name(
75
75
// The members must be `pub` for `links`.
76
76
/// The kind of the error.
@@ -80,6 +80,12 @@ macro_rules! impl_error_chain_processed {
80
80
pub $crate:: State <Trait >,
81
81
) ;
82
82
83
+ impl $crate:: ToError for $error_name {
84
+ fn to_error( & self ) -> & ( :: std:: error:: Error + Send + ' static ) {
85
+ self
86
+ }
87
+ }
88
+
83
89
impl $crate:: ChainedError <Trait > for $error_name {
84
90
type ErrorKind = $error_kind_name;
85
91
@@ -93,7 +99,7 @@ macro_rules! impl_error_chain_processed {
93
99
94
100
fn with_chain<E , K >( error: E , kind: K )
95
101
-> Self
96
- where E : :: std:: error:: Error + Send + ' static ,
102
+ where E : $crate :: ToError + :: std:: error:: Error + Send + ' static ,
97
103
K : Into <Self :: ErrorKind >
98
104
{
99
105
Self :: with_chain( error, kind)
@@ -135,7 +141,7 @@ macro_rules! impl_error_chain_processed {
135
141
/// Constructs a chained error from another error and a kind, and generates a backtrace.
136
142
pub fn with_chain<E , K >( error: E , kind: K )
137
143
-> $error_name
138
- where E : :: std :: error :: Error + Send + ' static ,
144
+ where E : Trait + ' static ,
139
145
K : Into <$error_kind_name>
140
146
{
141
147
$error_name:: with_boxed_chain( Box :: new( error) , kind)
@@ -188,7 +194,7 @@ macro_rules! impl_error_chain_processed {
188
194
#[ allow( unknown_lints, unused_doc_comment) ]
189
195
fn cause( & self ) -> Option <& :: std:: error:: Error > {
190
196
match self . 1 . next_error {
191
- Some ( ref c) => Some ( & * * c ) ,
197
+ Some ( ref c) => Some ( c . to_error ( ) ) ,
192
198
None => {
193
199
match self . 0 {
194
200
$(
@@ -257,7 +263,7 @@ macro_rules! impl_error_chain_processed {
257
263
258
264
impl_error_chain_kind! {
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,14 @@ macro_rules! impl_error_chain_processed {
326
332
EK : Into <$error_kind_name>;
327
333
}
328
334
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
+ {
330
338
fn chain_err<F , EK >( self , callback: F ) -> :: std:: result:: Result <T , $error_name>
331
339
where F : FnOnce ( ) -> EK ,
332
340
EK : Into <$error_kind_name> {
333
341
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) ) ;
335
343
$crate:: ChainedError :: new( callback( ) . into( ) , state)
336
344
} )
337
345
}
0 commit comments