@@ -379,32 +379,33 @@ pub trait ChainedError: error::Error + Send + 'static {
379
379
}
380
380
381
381
/// Additionnal methods for `Result`, for easy interaction with this crate.
382
- pub trait ResultExt < T , E : ChainedError > {
382
+ pub trait ResultExt < T , E , CE : ChainedError > {
383
383
/// If the `Result` is an `Err` then `chain_err` evaluates the closure,
384
384
/// which returns *some type that can be converted to `ErrorKind`*, boxes
385
385
/// the original error to store as the cause, then returns a new error
386
386
/// containing the original error.
387
- fn chain_err < F , EK > ( self , callback : F ) -> Result < T , E >
387
+ fn chain_err < F , EK > ( self , callback : F ) -> Result < T , CE >
388
388
where F : FnOnce ( ) -> EK ,
389
- EK : Into < E :: ErrorKind > ;
389
+ EK : Into < CE :: ErrorKind > ;
390
390
}
391
391
392
- impl < T , E > ResultExt < T , E > for Result < T , E > where E : ChainedError {
393
- fn chain_err < F , EK > ( self , callback : F ) -> Result < T , E >
392
+ impl < T , E , CE > ResultExt < T , E , CE > for Result < T , E > where CE : ChainedError , E : Into < CE > {
393
+ fn chain_err < F , EK > ( self , callback : F ) -> Result < T , CE >
394
394
where F : FnOnce ( ) -> EK ,
395
- EK : Into < E :: ErrorKind > {
395
+ EK : Into < CE :: ErrorKind > {
396
396
self . map_err ( move |e| {
397
+ let e = e. into ( ) ;
397
398
#[ cfg( feature = "backtrace" ) ]
398
399
let error = {
399
- let backtrace = E :: extract_backtrace ( & e)
400
+ let backtrace = CE :: extract_backtrace ( & e)
400
401
. unwrap_or_else ( make_backtrace) ;
401
- E :: new ( callback ( ) . into ( ) , State {
402
+ CE :: new ( callback ( ) . into ( ) , State {
402
403
next_error : Some ( Box :: new ( e) ) ,
403
404
backtrace : backtrace,
404
405
} )
405
406
} ;
406
407
#[ cfg( not( feature = "backtrace" ) ) ]
407
- let error = E :: new ( callback ( ) . into ( ) , State {
408
+ let error = CE :: new ( callback ( ) . into ( ) , State {
408
409
next_error : Some ( Box :: new ( e) ) ,
409
410
} ) ;
410
411
error
0 commit comments