Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Commit 6a12641

Browse files
authored
Merge pull request #290 from AnderEnder/compat_fix
Fix compat Error conversion
2 parents 946d6d5 + fc65810 commit 6a12641

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

src/compat.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ with_std! {
3939
}
4040
}
4141

42+
impl From<Error> for Box<StdError> {
43+
fn from(error: Error) -> Box<StdError> {
44+
Box::new(Compat { error })
45+
}
46+
}
47+
4248
impl From<Error> for Box<StdError + Send + Sync> {
4349
fn from(error: Error) -> Box<StdError + Send + Sync> {
4450
Box::new(Compat { error })

tests/fail_compat.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#[macro_use]
2+
extern crate failure;
3+
4+
use failure::Fail;
5+
6+
fn return_failure() -> Result<(), failure::Error> {
7+
#[derive(Fail, Debug)]
8+
#[fail(display = "my error")]
9+
struct MyError;
10+
11+
let err = MyError;
12+
Err(err.into())
13+
}
14+
15+
fn return_error() -> Result<(), Box<std::error::Error>> {
16+
return_failure()?;
17+
Ok(())
18+
}
19+
20+
fn return_error_send_sync() -> Result<(), Box<std::error::Error + Send + Sync>> {
21+
return_failure()?;
22+
Ok(())
23+
}
24+
25+
#[test]
26+
fn smoke_default_compat() {
27+
let err = return_error();
28+
assert!(err.is_err());
29+
}
30+
31+
#[test]
32+
fn smoke_compat_send_sync() {
33+
let err = return_error_send_sync();
34+
assert!(err.is_err());
35+
}

0 commit comments

Comments
 (0)