mirror of
https://github.com/haraldh/chainerror.git
synced 2025-01-31 00:56:41 +01:00
make ChainError Send + Sync
This commit is contained in:
parent
51af6da378
commit
a558c35ba4
|
@ -48,12 +48,12 @@ use std::error::Error;
|
|||
use std::io;
|
||||
use std::result::Result;
|
||||
|
||||
fn do_some_io() -> Result<(), Box<Error>> {
|
||||
fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func3() -> Result<(), Box<Error>> {
|
||||
fn func3() -> Result<(), Box<Error + Send + Sync>> {
|
||||
let filename = "foo.txt";
|
||||
do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?;
|
||||
Ok(())
|
||||
|
|
|
@ -8,7 +8,7 @@ a `std::error::Error`.
|
|||
Not using `String` errors anymore, the `cherr!()` macro seen in the beginning of
|
||||
the tutorial has to be used again.
|
||||
|
||||
Only returning `Func1ErrorKind` in `func1()` now let us get rid of `Result<(), Box<Error>>` and we can
|
||||
Only returning `Func1ErrorKind` in `func1()` now let us get rid of `Result<(), Box<Error + Send + Sync>>` and we can
|
||||
use `ChainResult<(), Func1ErrorKind>`.
|
||||
|
||||
In `main` we can now directly use the methods of `ChainError<T>` without downcasting the error first.
|
||||
|
|
|
@ -24,7 +24,7 @@ along with the filename (`file!()`) and line number (`line!()`)
|
|||
and returns `newerror`.
|
||||
|
||||
`Err()?` then returns the inner error applying `.into()`, so that we
|
||||
again have a `Err(Box<Error>)` as a result.
|
||||
again have a `Err(Box<Error + Send + Sync>)` as a result.
|
||||
|
||||
The `Debug` implementation of `ChainError<T>` (which is returned by `cherr!()`)
|
||||
prints the `Debug` of `T` prefixed with the stored filename and line number.
|
||||
|
|
|
@ -7,7 +7,7 @@ In this example `func1()` can return either `Func1ErrorFunc2` or `Func1ErrorIO`.
|
|||
We might want to `match` on `func1()` with something like:
|
||||
|
||||
~~~rust,ignore
|
||||
fn main() -> Result<(), Box<Error>> {
|
||||
fn main() -> Result<(), Box<Error + Send + Sync>> {
|
||||
match func1() {
|
||||
Err(e) if let Some(s) = e.downcast_chain_ref::<Func1ErrorIO>() =>
|
||||
eprintln!("Func1ErrorIO:\n{:?}", s),
|
||||
|
|
|
@ -3,12 +3,12 @@ use std::error::Error;
|
|||
use std::io;
|
||||
use std::result::Result;
|
||||
|
||||
fn do_some_io() -> Result<(), Box<Error>> {
|
||||
fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func3() -> Result<(), Box<Error>> {
|
||||
fn func3() -> Result<(), Box<Error + Send + Sync>> {
|
||||
let filename = "foo.txt";
|
||||
do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?;
|
||||
Ok(())
|
||||
|
|
|
@ -2,25 +2,25 @@ use std::error::Error;
|
|||
use std::io;
|
||||
use std::result::Result;
|
||||
|
||||
fn do_some_io() -> Result<(), Box<Error>> {
|
||||
fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func2() -> Result<(), Box<Error>> {
|
||||
fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
if let Err(_) = do_some_io() {
|
||||
Err("func2 error")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func1() -> Result<(), Box<Error>> {
|
||||
fn func1() -> Result<(), Box<Error + Send + Sync>> {
|
||||
if let Err(_) = func2() {
|
||||
Err("func1 error")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<Error>> {
|
||||
fn main() -> Result<(), Box<Error + Send + Sync>> {
|
||||
func1()
|
||||
}
|
||||
|
|
|
@ -3,14 +3,14 @@ use std::error::Error;
|
|||
use std::io;
|
||||
use std::result::Result;
|
||||
|
||||
fn do_some_io() -> Result<(), Box<Error>> {
|
||||
fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
derive_str_cherr!(Func2Error);
|
||||
|
||||
fn func2() -> Result<(), Box<Error>> {
|
||||
fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
let filename = "foo.txt";
|
||||
do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?;
|
||||
Ok(())
|
||||
|
@ -39,7 +39,7 @@ fn func1() -> ChainResult<(), Func1ErrorKind> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<Error>> {
|
||||
fn main() -> Result<(), Box<Error + Send + Sync>> {
|
||||
if let Err(e) = func1() {
|
||||
match e.kind() {
|
||||
Func1ErrorKind::Func2 => eprintln!("Main Error Report: func1 error calling func2"),
|
||||
|
|
|
@ -3,14 +3,14 @@ use std::error::Error;
|
|||
use std::io;
|
||||
use std::result::Result;
|
||||
|
||||
fn do_some_io() -> Result<(), Box<Error>> {
|
||||
fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
derive_str_cherr!(Func2Error);
|
||||
|
||||
fn func2() -> Result<(), Box<Error>> {
|
||||
fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
let filename = "foo.txt";
|
||||
do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?;
|
||||
Ok(())
|
||||
|
@ -45,7 +45,7 @@ fn func1() -> ChainResult<(), Func1ErrorKind> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<Error>> {
|
||||
fn main() -> Result<(), Box<Error + Send + Sync>> {
|
||||
if let Err(e) = func1() {
|
||||
match e.kind() {
|
||||
Func1ErrorKind::Func2 => eprintln!("Main Error Report: func1 error calling func2"),
|
||||
|
|
|
@ -3,14 +3,14 @@ use std::error::Error;
|
|||
use std::io;
|
||||
use std::result::Result;
|
||||
|
||||
fn do_some_io() -> Result<(), Box<Error>> {
|
||||
fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
derive_str_cherr!(Func2Error);
|
||||
|
||||
fn func2() -> Result<(), Box<Error>> {
|
||||
fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
let filename = "foo.txt";
|
||||
do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?;
|
||||
Ok(())
|
||||
|
@ -54,7 +54,7 @@ fn handle_func1errorkind(e: &Func1ErrorKind) {
|
|||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<Error>> {
|
||||
fn main() -> Result<(), Box<Error + Send + Sync>> {
|
||||
if let Err(e) = func1() {
|
||||
match *e {
|
||||
Func1ErrorKind::Func2 => eprintln!("Main Error Report: func1 error calling func2"),
|
||||
|
|
|
@ -2,14 +2,14 @@ pub mod mycrate {
|
|||
use chainerror::*;
|
||||
use std::io;
|
||||
|
||||
fn do_some_io() -> std::result::Result<(), Box<std::error::Error>> {
|
||||
fn do_some_io() -> std::result::Result<(), Box<std::error::Error + Send + Sync>> {
|
||||
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
derive_str_cherr!(Func2Error);
|
||||
|
||||
fn func2() -> std::result::Result<(), Box<std::error::Error>> {
|
||||
fn func2() -> std::result::Result<(), Box<std::error::Error + Send + Sync>> {
|
||||
let filename = "foo.txt";
|
||||
do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?;
|
||||
Ok(())
|
||||
|
|
|
@ -4,25 +4,25 @@ use std::error::Error;
|
|||
use std::io;
|
||||
use std::result::Result;
|
||||
|
||||
fn do_some_io() -> Result<(), Box<Error>> {
|
||||
fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func2() -> Result<(), Box<Error>> {
|
||||
fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
if let Err(e) = do_some_io() {
|
||||
Err(cherr!(e, "func2 error"))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func1() -> Result<(), Box<Error>> {
|
||||
fn func1() -> Result<(), Box<Error + Send + Sync>> {
|
||||
if let Err(e) = func2() {
|
||||
Err(cherr!(e, "func1 error"))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<Error>> {
|
||||
fn main() -> Result<(), Box<Error + Send + Sync>> {
|
||||
func1()
|
||||
}
|
||||
|
|
|
@ -4,22 +4,22 @@ use std::error::Error;
|
|||
use std::io;
|
||||
use std::result::Result;
|
||||
|
||||
fn do_some_io() -> Result<(), Box<Error>> {
|
||||
fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func2() -> Result<(), Box<Error>> {
|
||||
fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
do_some_io().map_err(|e| cherr!(e, "func2 error"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func1() -> Result<(), Box<Error>> {
|
||||
fn func1() -> Result<(), Box<Error + Send + Sync>> {
|
||||
func2().map_err(|e| cherr!(e, "func1 error"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<Error>> {
|
||||
fn main() -> Result<(), Box<Error + Send + Sync>> {
|
||||
if let Err(e) = func1() {
|
||||
eprintln!("{:?}", e);
|
||||
}
|
||||
|
|
|
@ -3,23 +3,23 @@ use std::error::Error;
|
|||
use std::io;
|
||||
use std::result::Result;
|
||||
|
||||
fn do_some_io() -> Result<(), Box<Error>> {
|
||||
fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func2() -> Result<(), Box<Error>> {
|
||||
fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
let filename = "foo.txt";
|
||||
do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func1() -> Result<(), Box<Error>> {
|
||||
fn func1() -> Result<(), Box<Error + Send + Sync>> {
|
||||
func2().map_err(mstrerr!("func1 error"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<Error>> {
|
||||
fn main() -> Result<(), Box<Error + Send + Sync>> {
|
||||
if let Err(e) = func1() {
|
||||
eprintln!("{:?}", e);
|
||||
}
|
||||
|
|
|
@ -3,18 +3,18 @@ use std::error::Error;
|
|||
use std::io;
|
||||
use std::result::Result;
|
||||
|
||||
fn do_some_io() -> Result<(), Box<Error>> {
|
||||
fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func2() -> Result<(), Box<Error>> {
|
||||
fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
let filename = "foo.txt";
|
||||
do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func1() -> Result<(), Box<Error>> {
|
||||
fn func1() -> Result<(), Box<Error + Send + Sync>> {
|
||||
if let Err(e) = func2() {
|
||||
if let Some(s) = e.source() {
|
||||
eprintln!("func2 failed because of '{}'", s);
|
||||
|
@ -24,7 +24,7 @@ fn func1() -> Result<(), Box<Error>> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<Error>> {
|
||||
fn main() -> Result<(), Box<Error + Send + Sync>> {
|
||||
if let Err(e) = func1() {
|
||||
eprintln!("{}", e);
|
||||
}
|
||||
|
|
|
@ -3,26 +3,26 @@ use std::error::Error;
|
|||
use std::io;
|
||||
use std::result::Result;
|
||||
|
||||
fn do_some_io() -> Result<(), Box<Error>> {
|
||||
fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func2() -> Result<(), Box<Error>> {
|
||||
fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
let filename = "foo.txt";
|
||||
do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func1() -> Result<(), Box<Error>> {
|
||||
fn func1() -> Result<(), Box<Error + Send + Sync>> {
|
||||
func2().map_err(mstrerr!("func1 error"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<Error>> {
|
||||
fn main() -> Result<(), Box<Error + Send + Sync>> {
|
||||
if let Err(e) = func1() {
|
||||
eprintln!("Error: {}", e);
|
||||
let mut s = e.as_ref();
|
||||
let mut s : &(dyn Error) = e.as_ref();
|
||||
while let Some(c) = s.source() {
|
||||
if let Some(ioerror) = c.downcast_ref::<io::Error>() {
|
||||
eprintln!("caused by: std::io::Error: {}", ioerror);
|
||||
|
|
|
@ -3,23 +3,23 @@ use std::error::Error;
|
|||
use std::io;
|
||||
use std::result::Result;
|
||||
|
||||
fn do_some_io() -> Result<(), Box<Error>> {
|
||||
fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func2() -> Result<(), Box<Error>> {
|
||||
fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
let filename = "foo.txt";
|
||||
do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn func1() -> Result<(), Box<Error>> {
|
||||
fn func1() -> Result<(), Box<Error + Send + Sync>> {
|
||||
func2().map_err(mstrerr!("func1 error"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<Error>> {
|
||||
fn main() -> Result<(), Box<Error + Send + Sync>> {
|
||||
if let Err(e) = func1() {
|
||||
eprintln!("Error: {}", e);
|
||||
if let Some(s) = e.downcast_chain_ref::<String>() {
|
||||
|
|
|
@ -3,14 +3,14 @@ use std::error::Error;
|
|||
use std::io;
|
||||
use std::result::Result;
|
||||
|
||||
fn do_some_io() -> Result<(), Box<Error>> {
|
||||
fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
derive_str_cherr!(Func2Error);
|
||||
|
||||
fn func2() -> Result<(), Box<Error>> {
|
||||
fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
let filename = "foo.txt";
|
||||
do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?;
|
||||
Ok(())
|
||||
|
@ -18,12 +18,12 @@ fn func2() -> Result<(), Box<Error>> {
|
|||
|
||||
derive_str_cherr!(Func1Error);
|
||||
|
||||
fn func1() -> Result<(), Box<Error>> {
|
||||
fn func1() -> Result<(), Box<Error + Send + Sync>> {
|
||||
func2().map_err(mstrerr!(Func1Error, "func1 error"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<Error>> {
|
||||
fn main() -> Result<(), Box<Error + Send + Sync>> {
|
||||
if let Err(e) = func1() {
|
||||
if let Some(f1err) = e.downcast_chain_ref::<Func1Error>() {
|
||||
eprintln!("Func1Error: {}", f1err);
|
||||
|
|
|
@ -3,14 +3,14 @@ use std::error::Error;
|
|||
use std::io;
|
||||
use std::result::Result;
|
||||
|
||||
fn do_some_io() -> Result<(), Box<Error>> {
|
||||
fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
derive_str_cherr!(Func2Error);
|
||||
|
||||
fn func2() -> Result<(), Box<Error>> {
|
||||
fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
let filename = "foo.txt";
|
||||
do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?;
|
||||
Ok(())
|
||||
|
@ -19,14 +19,14 @@ fn func2() -> Result<(), Box<Error>> {
|
|||
derive_str_cherr!(Func1ErrorFunc2);
|
||||
derive_str_cherr!(Func1ErrorIO);
|
||||
|
||||
fn func1() -> Result<(), Box<Error>> {
|
||||
fn func1() -> Result<(), Box<Error + Send + Sync>> {
|
||||
func2().map_err(mstrerr!(Func1ErrorFunc2, "func1 error calling func2"))?;
|
||||
let filename = "bar.txt";
|
||||
do_some_io().map_err(mstrerr!(Func1ErrorIO, "Error reading '{}'", filename))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<Error>> {
|
||||
fn main() -> Result<(), Box<Error + Send + Sync>> {
|
||||
if let Err(e) = func1() {
|
||||
if let Some(s) = e.downcast_ref::<ChainError<Func1ErrorIO>>() {
|
||||
eprintln!("Func1ErrorIO:\n{:?}", s);
|
||||
|
|
53
src/lib.rs
53
src/lib.rs
|
@ -32,18 +32,18 @@
|
|||
//! use std::io;
|
||||
//! use std::result::Result;
|
||||
//!
|
||||
//! fn do_some_io() -> Result<(), Box<Error>> {
|
||||
//! fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
//! Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
//! Ok(())
|
||||
//! }
|
||||
//!
|
||||
//! fn func2() -> Result<(), Box<Error>> {
|
||||
//! fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
//! let filename = "foo.txt";
|
||||
//! do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?;
|
||||
//! Ok(())
|
||||
//! }
|
||||
//!
|
||||
//! fn func1() -> Result<(), Box<Error>> {
|
||||
//! fn func1() -> Result<(), Box<Error + Send + Sync>> {
|
||||
//! func2().map_err(mstrerr!("func1 error"))?;
|
||||
//! Ok(())
|
||||
//! }
|
||||
|
@ -74,12 +74,12 @@
|
|||
//! use std::io;
|
||||
//! use std::result::Result;
|
||||
//!
|
||||
//! fn do_some_io() -> Result<(), Box<Error>> {
|
||||
//! fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
//! Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
//! Ok(())
|
||||
//! }
|
||||
//!
|
||||
//! fn func3() -> Result<(), Box<Error>> {
|
||||
//! fn func3() -> Result<(), Box<Error + Send + Sync>> {
|
||||
//! let filename = "foo.txt";
|
||||
//! do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?;
|
||||
//! Ok(())
|
||||
|
@ -175,7 +175,6 @@
|
|||
macro_use_extern_crate,
|
||||
missing_debug_implementations,
|
||||
missing_docs,
|
||||
trivial_casts,
|
||||
trivial_numeric_casts,
|
||||
unused_extern_crates,
|
||||
unused_import_braces,
|
||||
|
@ -201,7 +200,7 @@ pub struct ChainError<T> {
|
|||
#[cfg(not(feature = "no-fileline"))]
|
||||
occurrence: Option<&'static str>,
|
||||
kind: T,
|
||||
error_cause: Option<Box<dyn Error + 'static>>,
|
||||
error_cause: Option<Box<dyn Error + 'static + Send + Sync>>,
|
||||
}
|
||||
|
||||
/// convenience type alias
|
||||
|
@ -213,7 +212,7 @@ impl<T: 'static + Display + Debug> ChainError<T> {
|
|||
#[inline]
|
||||
pub fn new(
|
||||
kind: T,
|
||||
error_cause: Option<Box<dyn Error + 'static>>,
|
||||
error_cause: Option<Box<dyn Error + 'static + Send + Sync>>,
|
||||
occurrence: Option<&'static str>,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
@ -228,7 +227,7 @@ impl<T: 'static + Display + Debug> ChainError<T> {
|
|||
#[inline]
|
||||
pub fn new(
|
||||
kind: T,
|
||||
error_cause: Option<Box<dyn Error + 'static>>,
|
||||
error_cause: Option<Box<dyn Error + 'static + Send + Sync>>,
|
||||
_occurrence: Option<&'static str>,
|
||||
) -> Self {
|
||||
Self { kind, error_cause }
|
||||
|
@ -248,14 +247,14 @@ impl<T: 'static + Display + Debug> ChainError<T> {
|
|||
/// # use std::error::Error;
|
||||
/// # use std::io;
|
||||
/// # use std::result::Result;
|
||||
/// fn do_some_io() -> Result<(), Box<Error>> {
|
||||
/// fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
/// Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
/// Ok(())
|
||||
/// }
|
||||
///
|
||||
/// derive_str_cherr!(Func2Error);
|
||||
///
|
||||
/// fn func2() -> Result<(), Box<Error>> {
|
||||
/// fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
/// let filename = "foo.txt";
|
||||
/// do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?;
|
||||
/// Ok(())
|
||||
|
@ -263,7 +262,7 @@ impl<T: 'static + Display + Debug> ChainError<T> {
|
|||
///
|
||||
/// derive_str_cherr!(Func1Error);
|
||||
///
|
||||
/// fn func1() -> Result<(), Box<Error>> {
|
||||
/// fn func1() -> Result<(), Box<Error + Send + Sync>> {
|
||||
/// func2().map_err(mstrerr!(Func1Error, "func1 error"))?;
|
||||
/// Ok(())
|
||||
/// }
|
||||
|
@ -353,14 +352,14 @@ impl<T: 'static + Display + Debug> ChainError<T> {
|
|||
/// # use std::error::Error;
|
||||
/// # use std::io;
|
||||
/// # use std::result::Result;
|
||||
/// fn do_some_io() -> Result<(), Box<Error>> {
|
||||
/// fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
/// Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
/// Ok(())
|
||||
/// }
|
||||
///
|
||||
/// derive_str_cherr!(Func2Error);
|
||||
///
|
||||
/// fn func2() -> Result<(), Box<Error>> {
|
||||
/// fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
/// let filename = "foo.txt";
|
||||
/// do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?;
|
||||
/// Ok(())
|
||||
|
@ -539,21 +538,21 @@ impl ChainErrorDown for dyn Error + 'static + Send + Sync {
|
|||
impl<T: 'static + Display + Debug> Error for ChainError<T> {
|
||||
#[inline]
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||
self.error_cause.as_ref().map(|e| e.as_ref())
|
||||
self.error_cause.as_ref().map(|e| e.as_ref() as &(dyn Error + 'static))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: 'static + Display + Debug> Error for &ChainError<T> {
|
||||
#[inline]
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||
self.error_cause.as_ref().map(|e| e.as_ref())
|
||||
self.error_cause.as_ref().map(|e| e.as_ref() as &(dyn Error + 'static))
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: 'static + Display + Debug> Error for &mut ChainError<T> {
|
||||
#[inline]
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||
self.error_cause.as_ref().map(|e| e.as_ref())
|
||||
self.error_cause.as_ref().map(|e| e.as_ref() as &(dyn Error + 'static))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -714,7 +713,7 @@ macro_rules! into_cherr {
|
|||
/// # }
|
||||
/// # }
|
||||
/// # }
|
||||
/// fn do_some_stuff() -> Result<(), Box<Error>> {
|
||||
/// fn do_some_stuff() -> Result<(), Box<Error + Send + Sync>> {
|
||||
/// Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
/// Ok(())
|
||||
/// }
|
||||
|
@ -772,17 +771,17 @@ macro_rules! mcherr {
|
|||
/// # use std::error::Error;
|
||||
/// # use std::io;
|
||||
/// # use std::result::Result;
|
||||
/// # fn do_some_io() -> Result<(), Box<Error>> {
|
||||
/// # fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
/// # Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// fn func2() -> Result<(), Box<Error>> {
|
||||
/// fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
/// let filename = "foo.txt";
|
||||
/// do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?;
|
||||
/// Ok(())
|
||||
/// }
|
||||
///
|
||||
/// fn func1() -> Result<(), Box<Error>> {
|
||||
/// fn func1() -> Result<(), Box<Error + Send + Sync>> {
|
||||
/// func2().map_err(mstrerr!("func1 error"))?;
|
||||
/// Ok(())
|
||||
/// }
|
||||
|
@ -813,13 +812,13 @@ macro_rules! mcherr {
|
|||
/// # use std::error::Error;
|
||||
/// # use std::io;
|
||||
/// # use std::result::Result;
|
||||
/// # fn do_some_io() -> Result<(), Box<Error>> {
|
||||
/// # fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
/// # Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
/// derive_str_cherr!(Func2Error);
|
||||
///
|
||||
/// fn func2() -> Result<(), Box<Error>> {
|
||||
/// fn func2() -> Result<(), Box<Error + Send + Sync>> {
|
||||
/// let filename = "foo.txt";
|
||||
/// do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?;
|
||||
/// Ok(())
|
||||
|
@ -827,7 +826,7 @@ macro_rules! mcherr {
|
|||
///
|
||||
/// derive_str_cherr!(Func1Error);
|
||||
///
|
||||
/// fn func1() -> Result<(), Box<Error>> {
|
||||
/// fn func1() -> Result<(), Box<Error + Send + Sync>> {
|
||||
/// func2().map_err(mstrerr!(Func1Error, "func1 error"))?;
|
||||
/// Ok(())
|
||||
/// }
|
||||
|
@ -883,7 +882,7 @@ macro_rules! mstrerr {
|
|||
///
|
||||
/// derive_str_cherr!(Func1Error);
|
||||
///
|
||||
/// fn func1() -> Result<(), Box<Error>> {
|
||||
/// fn func1() -> Result<(), Box<Error + Send + Sync>> {
|
||||
/// func2().map_err(mstrerr!(Func1Error, "func1 error"))?;
|
||||
/// Ok(())
|
||||
/// }
|
||||
|
@ -931,7 +930,7 @@ macro_rules! strerr {
|
|||
/// # use std::error::Error;
|
||||
/// # use std::io;
|
||||
/// # use std::result::Result;
|
||||
/// # fn do_some_io() -> Result<(), Box<Error>> {
|
||||
/// # fn do_some_io() -> Result<(), Box<Error + Send + Sync>> {
|
||||
/// # Err(io::Error::from(io::ErrorKind::NotFound))?;
|
||||
/// # Ok(())
|
||||
/// # }
|
||||
|
@ -945,7 +944,7 @@ macro_rules! strerr {
|
|||
///
|
||||
/// derive_str_cherr!(Func1Error);
|
||||
///
|
||||
/// fn func1() -> Result<(), Box<Error>> {
|
||||
/// fn func1() -> Result<(), Box<Error + Send + Sync>> {
|
||||
/// func2().map_err(mstrerr!(Func1Error, "func1 error"))?;
|
||||
/// Ok(())
|
||||
/// }
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::fmt::Write;
|
|||
use std::io;
|
||||
|
||||
#[test]
|
||||
fn test_iter() -> Result<(), Box<Error>> {
|
||||
fn test_iter() -> Result<(), Box<Error + Send + Sync>> {
|
||||
let err = io::Error::from(io::ErrorKind::NotFound);
|
||||
let err = cherr!(err, "1");
|
||||
let err = cherr!(err, "2");
|
||||
|
@ -31,7 +31,7 @@ fn test_iter() -> Result<(), Box<Error>> {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_cause() -> Result<(), Box<Error>> {
|
||||
fn test_find_cause() -> Result<(), Box<Error + Send + Sync>> {
|
||||
let err = io::Error::from(io::ErrorKind::NotFound);
|
||||
let err = cherr!(err, "1");
|
||||
let err = cherr!(err, "2");
|
||||
|
@ -48,7 +48,7 @@ fn test_find_cause() -> Result<(), Box<Error>> {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_root_cause() -> Result<(), Box<Error>> {
|
||||
fn test_root_cause() -> Result<(), Box<Error + Send + Sync>> {
|
||||
let err = io::Error::from(io::ErrorKind::NotFound);
|
||||
let err = cherr!(err, "1");
|
||||
let err = cherr!(err, "2");
|
||||
|
|
Loading…
Reference in a new issue