aserror: support Send + !Sync errors too

This commit is contained in:
Ben Boeckel 2019-11-18 22:14:23 -05:00
parent eb052728d4
commit 4303f71cce
2 changed files with 23 additions and 1 deletions

View File

@ -18,6 +18,13 @@ impl AsDynError for dyn Error + 'static {
}
}
impl AsDynError for dyn Error + Send + 'static {
#[inline]
fn as_dyn_error(&self) -> &(dyn Error + 'static) {
self
}
}
impl AsDynError for dyn Error + Send + Sync + 'static {
#[inline]
fn as_dyn_error(&self) -> &(dyn Error + 'static) {

View File

@ -1,4 +1,4 @@
use std::error::Error as _;
use std::error::Error;
use std::io;
use thiserror::Error;
@ -16,6 +16,13 @@ pub struct ExplicitSource {
io: io::Error,
}
#[derive(Error, Debug)]
#[error("boxed source")]
pub struct BoxedSource {
#[source]
source: Box<dyn Error + Send + 'static>,
}
#[test]
fn test_implicit_source() {
let io = io::Error::new(io::ErrorKind::Other, "oh no!");
@ -32,3 +39,11 @@ fn test_explicit_source() {
};
error.source().unwrap().downcast_ref::<io::Error>().unwrap();
}
#[test]
fn test_boxed_source() {
let io = io::Error::new(io::ErrorKind::Other, "oh no!");
let _error = BoxedSource {
source: Box::new(io),
};
}