diff --git a/examples/example.rs b/examples/example.rs index c383000..99f965e 100644 --- a/examples/example.rs +++ b/examples/example.rs @@ -4,12 +4,12 @@ use std::result::Result; use chainerror::*; -fn do_some_io() -> Result<(), Box> { +fn do_some_io() -> Result<(), Box> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } -fn func3() -> Result<(), Box> { +fn func3() -> Result<(), Box> { let filename = "foo.txt"; do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?; Ok(()) diff --git a/examples/tutorial1.rs b/examples/tutorial1.rs index d296a92..4ac1eb3 100644 --- a/examples/tutorial1.rs +++ b/examples/tutorial1.rs @@ -2,25 +2,25 @@ use std::error::Error; use std::io; use std::result::Result; -fn do_some_io() -> Result<(), Box> { +fn do_some_io() -> Result<(), Box> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } -fn func2() -> Result<(), Box> { +fn func2() -> Result<(), Box> { if let Err(_) = do_some_io() { Err("func2 error")?; } Ok(()) } -fn func1() -> Result<(), Box> { +fn func1() -> Result<(), Box> { if let Err(_) = func2() { Err("func1 error")?; } Ok(()) } -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { func1() } diff --git a/examples/tutorial10.rs b/examples/tutorial10.rs index 15eae31..cf13909 100644 --- a/examples/tutorial10.rs +++ b/examples/tutorial10.rs @@ -3,14 +3,14 @@ use std::error::Error; use std::io; use std::result::Result; -fn do_some_io() -> Result<(), Box> { +fn do_some_io() -> Result<(), Box> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } derive_str_cherr!(Func2Error); -fn func2() -> Result<(), Box> { +fn func2() -> Result<(), Box> { 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> { +fn main() -> Result<(), Box> { if let Err(e) = func1() { match e.kind() { Func1ErrorKind::Func2 => eprintln!("Main Error Report: func1 error calling func2"), diff --git a/examples/tutorial11.rs b/examples/tutorial11.rs index 00e3d74..5f85c23 100644 --- a/examples/tutorial11.rs +++ b/examples/tutorial11.rs @@ -3,14 +3,14 @@ use std::error::Error; use std::io; use std::result::Result; -fn do_some_io() -> Result<(), Box> { +fn do_some_io() -> Result<(), Box> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } derive_str_cherr!(Func2Error); -fn func2() -> Result<(), Box> { +fn func2() -> Result<(), Box> { 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> { +fn main() -> Result<(), Box> { if let Err(e) = func1() { match e.kind() { Func1ErrorKind::Func2 => eprintln!("Main Error Report: func1 error calling func2"), diff --git a/examples/tutorial12.rs b/examples/tutorial12.rs index 8cdc8aa..f5e38de 100644 --- a/examples/tutorial12.rs +++ b/examples/tutorial12.rs @@ -3,14 +3,14 @@ use std::error::Error; use std::io; use std::result::Result; -fn do_some_io() -> Result<(), Box> { +fn do_some_io() -> Result<(), Box> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } derive_str_cherr!(Func2Error); -fn func2() -> Result<(), Box> { +fn func2() -> Result<(), Box> { 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> { +fn main() -> Result<(), Box> { if let Err(e) = func1() { match *e { Func1ErrorKind::Func2 => eprintln!("Main Error Report: func1 error calling func2"), diff --git a/examples/tutorial13.rs b/examples/tutorial13.rs index 78dee31..c345157 100644 --- a/examples/tutorial13.rs +++ b/examples/tutorial13.rs @@ -2,14 +2,14 @@ pub mod mycrate { use chainerror::*; use std::io; - fn do_some_io() -> std::result::Result<(), Box> { + fn do_some_io() -> std::result::Result<(), Box> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } derive_str_cherr!(Func2Error); - fn func2() -> std::result::Result<(), Box> { + fn func2() -> std::result::Result<(), Box> { let filename = "foo.txt"; do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?; Ok(()) @@ -42,7 +42,7 @@ pub mod mycrate { } } -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { use mycrate::func1; use mycrate::ErrorKind; use std::error::Error; @@ -57,7 +57,7 @@ fn main() -> Result<(), Box> { } eprintln!(); - let mut s: &Error = &e; + let mut s: &dyn Error = &e; while let Some(c) = s.source() { if let Some(ioerror) = c.downcast_ref::() { eprintln!("caused by: std::io::Error: {}", ioerror); diff --git a/examples/tutorial14.rs b/examples/tutorial14.rs index e73d747..84c3491 100644 --- a/examples/tutorial14.rs +++ b/examples/tutorial14.rs @@ -182,7 +182,7 @@ pub mod mycrate { } } -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { use mycrate::func1; use mycrate::ErrorKind; use std::error::Error; @@ -197,7 +197,7 @@ fn main() -> Result<(), Box> { } eprintln!(); - let mut s: &Error = &e; + let mut s: &dyn Error = &e; while let Some(c) = s.source() { if let Some(ioerror) = c.downcast_ref::() { eprintln!("caused by: std::io::Error: {}", ioerror); diff --git a/examples/tutorial15.rs b/examples/tutorial15.rs index c0f5fe7..581840c 100644 --- a/examples/tutorial15.rs +++ b/examples/tutorial15.rs @@ -10,7 +10,7 @@ pub mod mycrate { derive_str_cherr!(Func2Error); - fn func2() -> std::result::Result<(), Box> { + fn func2() -> std::result::Result<(), Box> { let filename = "foo.txt"; do_some_io(filename) .map_err(|e| cherr!(e, Func2Error(format!("Error reading '{}'", filename))))?; @@ -52,7 +52,7 @@ pub mod mycrate { } impl From<&(dyn std::error::Error + 'static + Send + Sync)> for ErrorKind { - fn from(e: &(dyn std::error::Error + 'static + Send + Sync)) -> Self { + fn from(e: &(dyn std::error::Error + 'static + Send + Sync)) -> Self { if let Some(_) = e.downcast_ref::() { ErrorKind::IO(String::from("Unknown filename")) } else if let Some(_) = e.downcast_inner_ref::() { @@ -63,8 +63,8 @@ pub mod mycrate { } } - impl From<&std::boxed::Box> for ErrorKind { - fn from(e: &std::boxed::Box) -> Self { + impl From<&std::boxed::Box> for ErrorKind { + fn from(e: &std::boxed::Box) -> Self { Self::from(&**e) } } @@ -99,10 +99,9 @@ pub mod mycrate { func1().map_err(minto_cherr!(ErrorKind))?; Ok(()) } - } -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { use mycrate::super_func1; use mycrate::ErrorKind; use std::error::Error; @@ -119,7 +118,7 @@ fn main() -> Result<(), Box> { } eprintln!(); - let mut s: &Error = &e; + let mut s: &dyn Error = &e; while let Some(c) = s.source() { if let Some(ioerror) = c.downcast_ref::() { eprintln!("caused by: std::io::Error: {}", ioerror); diff --git a/examples/tutorial2.rs b/examples/tutorial2.rs index 349c5cd..b13f0cc 100644 --- a/examples/tutorial2.rs +++ b/examples/tutorial2.rs @@ -4,25 +4,25 @@ use std::error::Error; use std::io; use std::result::Result; -fn do_some_io() -> Result<(), Box> { +fn do_some_io() -> Result<(), Box> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } -fn func2() -> Result<(), Box> { +fn func2() -> Result<(), Box> { if let Err(e) = do_some_io() { Err(cherr!(e, "func2 error"))?; } Ok(()) } -fn func1() -> Result<(), Box> { +fn func1() -> Result<(), Box> { if let Err(e) = func2() { Err(cherr!(e, "func1 error"))?; } Ok(()) } -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { func1() } diff --git a/examples/tutorial3.rs b/examples/tutorial3.rs index cdbffed..6da067c 100644 --- a/examples/tutorial3.rs +++ b/examples/tutorial3.rs @@ -4,22 +4,22 @@ use std::error::Error; use std::io; use std::result::Result; -fn do_some_io() -> Result<(), Box> { +fn do_some_io() -> Result<(), Box> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } -fn func2() -> Result<(), Box> { +fn func2() -> Result<(), Box> { do_some_io().map_err(|e| cherr!(e, "func2 error"))?; Ok(()) } -fn func1() -> Result<(), Box> { +fn func1() -> Result<(), Box> { func2().map_err(|e| cherr!(e, "func1 error"))?; Ok(()) } -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { if let Err(e) = func1() { eprintln!("{:?}", e); } diff --git a/examples/tutorial4.rs b/examples/tutorial4.rs index d037215..e1225c0 100644 --- a/examples/tutorial4.rs +++ b/examples/tutorial4.rs @@ -3,23 +3,23 @@ use std::error::Error; use std::io; use std::result::Result; -fn do_some_io() -> Result<(), Box> { +fn do_some_io() -> Result<(), Box> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } -fn func2() -> Result<(), Box> { +fn func2() -> Result<(), Box> { let filename = "foo.txt"; do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?; Ok(()) } -fn func1() -> Result<(), Box> { +fn func1() -> Result<(), Box> { func2().map_err(mstrerr!("func1 error"))?; Ok(()) } -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { if let Err(e) = func1() { eprintln!("{:?}", e); } diff --git a/examples/tutorial5.rs b/examples/tutorial5.rs index 4d673e3..cb80569 100644 --- a/examples/tutorial5.rs +++ b/examples/tutorial5.rs @@ -3,18 +3,18 @@ use std::error::Error; use std::io; use std::result::Result; -fn do_some_io() -> Result<(), Box> { +fn do_some_io() -> Result<(), Box> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } -fn func2() -> Result<(), Box> { +fn func2() -> Result<(), Box> { let filename = "foo.txt"; do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?; Ok(()) } -fn func1() -> Result<(), Box> { +fn func1() -> Result<(), Box> { 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> { Ok(()) } -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { if let Err(e) = func1() { eprintln!("{}", e); } diff --git a/examples/tutorial6.rs b/examples/tutorial6.rs index 22e0e78..996540c 100644 --- a/examples/tutorial6.rs +++ b/examples/tutorial6.rs @@ -3,26 +3,26 @@ use std::error::Error; use std::io; use std::result::Result; -fn do_some_io() -> Result<(), Box> { +fn do_some_io() -> Result<(), Box> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } -fn func2() -> Result<(), Box> { +fn func2() -> Result<(), Box> { let filename = "foo.txt"; do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?; Ok(()) } -fn func1() -> Result<(), Box> { +fn func1() -> Result<(), Box> { func2().map_err(mstrerr!("func1 error"))?; Ok(()) } -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { if let Err(e) = func1() { eprintln!("Error: {}", e); - let mut s : &(dyn Error) = e.as_ref(); + let mut s: &(dyn Error) = e.as_ref(); while let Some(c) = s.source() { if let Some(ioerror) = c.downcast_ref::() { eprintln!("caused by: std::io::Error: {}", ioerror); diff --git a/examples/tutorial7.rs b/examples/tutorial7.rs index bf09449..b36fa8b 100644 --- a/examples/tutorial7.rs +++ b/examples/tutorial7.rs @@ -3,23 +3,23 @@ use std::error::Error; use std::io; use std::result::Result; -fn do_some_io() -> Result<(), Box> { +fn do_some_io() -> Result<(), Box> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } -fn func2() -> Result<(), Box> { +fn func2() -> Result<(), Box> { let filename = "foo.txt"; do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?; Ok(()) } -fn func1() -> Result<(), Box> { +fn func1() -> Result<(), Box> { func2().map_err(mstrerr!("func1 error"))?; Ok(()) } -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { if let Err(e) = func1() { eprintln!("Error: {}", e); if let Some(s) = e.downcast_chain_ref::() { diff --git a/examples/tutorial8.rs b/examples/tutorial8.rs index be92df7..1644a32 100644 --- a/examples/tutorial8.rs +++ b/examples/tutorial8.rs @@ -3,14 +3,14 @@ use std::error::Error; use std::io; use std::result::Result; -fn do_some_io() -> Result<(), Box> { +fn do_some_io() -> Result<(), Box> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } derive_str_cherr!(Func2Error); -fn func2() -> Result<(), Box> { +fn func2() -> Result<(), Box> { let filename = "foo.txt"; do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?; Ok(()) @@ -18,12 +18,12 @@ fn func2() -> Result<(), Box> { derive_str_cherr!(Func1Error); -fn func1() -> Result<(), Box> { +fn func1() -> Result<(), Box> { func2().map_err(mstrerr!(Func1Error, "func1 error"))?; Ok(()) } -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { if let Err(e) = func1() { if let Some(f1err) = e.downcast_chain_ref::() { eprintln!("Func1Error: {}", f1err); diff --git a/examples/tutorial9.rs b/examples/tutorial9.rs index d9436f4..99b0f23 100644 --- a/examples/tutorial9.rs +++ b/examples/tutorial9.rs @@ -3,14 +3,14 @@ use std::error::Error; use std::io; use std::result::Result; -fn do_some_io() -> Result<(), Box> { +fn do_some_io() -> Result<(), Box> { Err(io::Error::from(io::ErrorKind::NotFound))?; Ok(()) } derive_str_cherr!(Func2Error); -fn func2() -> Result<(), Box> { +fn func2() -> Result<(), Box> { let filename = "foo.txt"; do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?; Ok(()) @@ -19,14 +19,14 @@ fn func2() -> Result<(), Box> { derive_str_cherr!(Func1ErrorFunc2); derive_str_cherr!(Func1ErrorIO); -fn func1() -> Result<(), Box> { +fn func1() -> Result<(), Box> { 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> { +fn main() -> Result<(), Box> { if let Err(e) = func1() { if let Some(s) = e.downcast_ref::>() { eprintln!("Func1ErrorIO:\n{:?}", s); diff --git a/src/lib.rs b/src/lib.rs index f378585..d68a1b6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,18 +32,18 @@ //! use std::io; //! use std::result::Result; //! -//! fn do_some_io() -> Result<(), Box> { +//! fn do_some_io() -> Result<(), Box> { //! Err(io::Error::from(io::ErrorKind::NotFound))?; //! Ok(()) //! } //! -//! fn func2() -> Result<(), Box> { +//! fn func2() -> Result<(), Box> { //! let filename = "foo.txt"; //! do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?; //! Ok(()) //! } //! -//! fn func1() -> Result<(), Box> { +//! fn func1() -> Result<(), Box> { //! func2().map_err(mstrerr!("func1 error"))?; //! Ok(()) //! } @@ -74,12 +74,12 @@ //! use std::io; //! use std::result::Result; //! -//! fn do_some_io() -> Result<(), Box> { +//! fn do_some_io() -> Result<(), Box> { //! Err(io::Error::from(io::ErrorKind::NotFound))?; //! Ok(()) //! } //! -//! fn func3() -> Result<(), Box> { +//! fn func3() -> Result<(), Box> { //! let filename = "foo.txt"; //! do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?; //! Ok(()) @@ -246,14 +246,14 @@ impl ChainError { /// use std::error::Error; /// use std::io; /// - /// fn do_some_io() -> Result<(), Box> { + /// fn do_some_io() -> Result<(), Box> { /// Err(io::Error::from(io::ErrorKind::NotFound))?; /// Ok(()) /// } /// /// derive_str_cherr!(Func2Error); /// - /// fn func2() -> Result<(), Box> { + /// fn func2() -> Result<(), Box> { /// let filename = "foo.txt"; /// do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?; /// Ok(()) @@ -261,7 +261,7 @@ impl ChainError { /// /// derive_str_cherr!(Func1Error); /// - /// fn func1() -> Result<(), Box> { + /// fn func1() -> Result<(), Box> { /// func2().map_err(mstrerr!(Func1Error, "func1 error"))?; /// Ok(()) /// } @@ -351,14 +351,14 @@ impl ChainError { /// use std::error::Error; /// use std::io; /// - /// fn do_some_io() -> Result<(), Box> { + /// fn do_some_io() -> Result<(), Box> { /// Err(io::Error::from(io::ErrorKind::NotFound))?; /// Ok(()) /// } /// /// derive_str_cherr!(Func2Error); /// - /// fn func2() -> Result<(), Box> { + /// fn func2() -> Result<(), Box> { /// let filename = "foo.txt"; /// do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?; /// Ok(()) @@ -801,7 +801,7 @@ macro_rules! minto_cherr { /// # } /// # } /// # } -/// fn do_some_stuff() -> Result<(), Box> { +/// fn do_some_stuff() -> Result<(), Box> { /// Err(io::Error::from(io::ErrorKind::NotFound))?; /// Ok(()) /// } @@ -850,17 +850,17 @@ macro_rules! cherr { /// # use std::error::Error; /// # use std::io; /// # use std::result::Result; -/// # fn do_some_io() -> Result<(), Box> { +/// # fn do_some_io() -> Result<(), Box> { /// # Err(io::Error::from(io::ErrorKind::NotFound))?; /// # Ok(()) /// # } -/// fn func2() -> Result<(), Box> { +/// fn func2() -> Result<(), Box> { /// let filename = "foo.txt"; /// do_some_io().map_err(mstrerr!("Error reading '{}'", filename))?; /// Ok(()) /// } /// -/// fn func1() -> Result<(), Box> { +/// fn func1() -> Result<(), Box> { /// func2().map_err(mstrerr!("func1 error"))?; /// Ok(()) /// } @@ -891,13 +891,13 @@ macro_rules! cherr { /// # use std::error::Error; /// # use std::io; /// # use std::result::Result; -/// # fn do_some_io() -> Result<(), Box> { +/// # fn do_some_io() -> Result<(), Box> { /// # Err(io::Error::from(io::ErrorKind::NotFound))?; /// # Ok(()) /// # } /// derive_str_cherr!(Func2Error); /// -/// fn func2() -> Result<(), Box> { +/// fn func2() -> Result<(), Box> { /// let filename = "foo.txt"; /// do_some_io().map_err(mstrerr!(Func2Error, "Error reading '{}'", filename))?; /// Ok(()) @@ -905,7 +905,7 @@ macro_rules! cherr { /// /// derive_str_cherr!(Func1Error); /// -/// fn func1() -> Result<(), Box> { +/// fn func1() -> Result<(), Box> { /// func2().map_err(mstrerr!(Func1Error, "func1 error"))?; /// Ok(()) /// } @@ -961,7 +961,7 @@ macro_rules! mstrerr { /// /// derive_str_cherr!(Func1Error); /// -/// fn func1() -> Result<(), Box> { +/// fn func1() -> Result<(), Box> { /// func2().map_err(mstrerr!(Func1Error, "func1 error"))?; /// Ok(()) /// } @@ -1009,7 +1009,7 @@ macro_rules! strerr { /// # use std::error::Error; /// # use std::io; /// # use std::result::Result; -/// # fn do_some_io() -> Result<(), Box> { +/// # fn do_some_io() -> Result<(), Box> { /// # Err(io::Error::from(io::ErrorKind::NotFound))?; /// # Ok(()) /// # } @@ -1023,7 +1023,7 @@ macro_rules! strerr { /// /// derive_str_cherr!(Func1Error); /// -/// fn func1() -> Result<(), Box> { +/// fn func1() -> Result<(), Box> { /// func2().map_err(mstrerr!(Func1Error, "func1 error"))?; /// Ok(()) /// } diff --git a/tests/test_iter.rs b/tests/test_iter.rs index c451f7f..488ed0b 100644 --- a/tests/test_iter.rs +++ b/tests/test_iter.rs @@ -4,7 +4,7 @@ use std::fmt::Write; use std::io; #[test] -fn test_iter() -> Result<(), Box> { +fn test_iter() -> Result<(), Box> { 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> { } #[test] -fn test_find_cause() -> Result<(), Box> { +fn test_find_cause() -> Result<(), Box> { 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> { } #[test] -fn test_root_cause() -> Result<(), Box> { +fn test_root_cause() -> Result<(), Box> { let err = io::Error::from(io::ErrorKind::NotFound); let err = cherr!(err, "1"); let err = cherr!(err, "2");