@@ -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,12 +139,12 @@ 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(
140
146
kind. into( ) ,
141
- $crate:: State :: new:: <$error_name>( Box :: new( error) , ) ,
147
+ $crate:: State :: new:: <$error_name>( Box :: new( error) ) ,
142
148
)
143
149
}
144
150
@@ -171,7 +177,7 @@ macro_rules! error_chain_processed {
171
177
172
178
fn cause( & self ) -> Option <& :: std:: error:: Error > {
173
179
match self . 1 . next_error {
174
- Some ( ref c) => Some ( & * * c ) ,
180
+ Some ( ref c) => Some ( c . to_error ( ) ) ,
175
181
None => {
176
182
match self . 0 {
177
183
$(
@@ -248,7 +254,7 @@ macro_rules! error_chain_processed {
248
254
249
255
quick_error! {
250
256
/// The kind of an error.
251
- #[ derive( Debug , $( $bound ) ,* ) ]
257
+ #[ derive( Debug , $( $derive ) ,* ) ]
252
258
pub enum $error_kind_name {
253
259
254
260
/// A convenient variant for String.
@@ -317,12 +323,14 @@ macro_rules! error_chain_processed {
317
323
EK : Into <$error_kind_name>;
318
324
}
319
325
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
+ {
321
329
fn chain_err<F , EK >( self , callback: F ) -> :: std:: result:: Result <T , $error_name>
322
330
where F : FnOnce ( ) -> EK ,
323
331
EK : Into <$error_kind_name> {
324
332
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) ) ;
326
334
$crate:: ChainedError :: new( callback( ) . into( ) , state)
327
335
} )
328
336
}
0 commit comments