aserror: support Send + !Sync errors too
This commit is contained in:
parent
eb052728d4
commit
4303f71cce
|
@ -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) {
|
||||
|
|
|
@ -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),
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue