mirror of
https://github.com/haraldh/chainerror.git
synced 2025-01-31 00:56:41 +01:00
remove main
in doc tests and cargo fmt
the doc tests
This commit is contained in:
parent
174d81c8d9
commit
241502de75
58
src/lib.rs
58
src/lib.rs
|
@ -48,14 +48,14 @@
|
||||||
//! Ok(())
|
//! Ok(())
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! fn main() {
|
|
||||||
//! if let Err(e) = func1() {
|
//! if let Err(e) = func1() {
|
||||||
//! #[cfg(not(windows))]
|
//! #[cfg(not(windows))]
|
||||||
//! assert_eq!(
|
//! assert_eq!(
|
||||||
//! format!("\n{:?}\n", e), r#"
|
//! format!("\n{:?}\n", e),
|
||||||
//! src/lib.rs:20: func1 error
|
//! r#"
|
||||||
|
//! src/lib.rs:21: func1 error
|
||||||
//! Caused by:
|
//! Caused by:
|
||||||
//! src/lib.rs:15: Error reading 'foo.txt'
|
//! src/lib.rs:16: Error reading 'foo.txt'
|
||||||
//! Caused by:
|
//! Caused by:
|
||||||
//! Kind(NotFound)
|
//! Kind(NotFound)
|
||||||
//! "#
|
//! "#
|
||||||
|
@ -64,7 +64,6 @@
|
||||||
//! # else {
|
//! # else {
|
||||||
//! # unreachable!();
|
//! # unreachable!();
|
||||||
//! # }
|
//! # }
|
||||||
//! }
|
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
//!
|
//!
|
||||||
|
@ -119,10 +118,8 @@
|
||||||
//! Ok(())
|
//! Ok(())
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! fn main() {
|
|
||||||
//! if let Err(e) = func1() {
|
//! if let Err(e) = func1() {
|
||||||
//! assert!(
|
//! assert!(match e.kind() {
|
||||||
//! match e.kind() {
|
|
||||||
//! Func1Error::Func2 => {
|
//! Func1Error::Func2 => {
|
||||||
//! eprintln!("Main Error Report: func1 error calling func2");
|
//! eprintln!("Main Error Report: func1 error calling func2");
|
||||||
//! true
|
//! true
|
||||||
|
@ -131,8 +128,7 @@
|
||||||
//! eprintln!("Main Error Report: func1 error reading '{}'", filename);
|
//! eprintln!("Main Error Report: func1 error reading '{}'", filename);
|
||||||
//! false
|
//! false
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! });
|
||||||
//! );
|
|
||||||
//!
|
//!
|
||||||
//! assert!(e.find_chain_cause::<Func2Error>().is_some());
|
//! assert!(e.find_chain_cause::<Func2Error>().is_some());
|
||||||
//!
|
//!
|
||||||
|
@ -140,7 +136,6 @@
|
||||||
//! eprintln!("\nError reported by Func2Error: {}", e)
|
//! eprintln!("\nError reported by Func2Error: {}", e)
|
||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//!
|
|
||||||
//! assert!(e.root_cause().is_some());
|
//! assert!(e.root_cause().is_some());
|
||||||
//!
|
//!
|
||||||
//! if let Some(e) = e.root_cause() {
|
//! if let Some(e) = e.root_cause() {
|
||||||
|
@ -150,12 +145,13 @@
|
||||||
//!
|
//!
|
||||||
//! #[cfg(not(windows))]
|
//! #[cfg(not(windows))]
|
||||||
//! assert_eq!(
|
//! assert_eq!(
|
||||||
//! format!("\n{:?}\n", e), r#"
|
//! format!("\n{:?}\n", e),
|
||||||
//! src/lib.rs:47: func1 error calling func2
|
//! r#"
|
||||||
|
//! src/lib.rs:48: func1 error calling func2
|
||||||
//! Caused by:
|
//! Caused by:
|
||||||
//! src/lib.rs:22: Func2Error(func2 error: calling func3)
|
//! src/lib.rs:23: Func2Error(func2 error: calling func3)
|
||||||
//! Caused by:
|
//! Caused by:
|
||||||
//! src/lib.rs:15: Error reading 'foo.txt'
|
//! src/lib.rs:16: Error reading 'foo.txt'
|
||||||
//! Caused by:
|
//! Caused by:
|
||||||
//! Kind(NotFound)
|
//! Kind(NotFound)
|
||||||
//! "#
|
//! "#
|
||||||
|
@ -164,7 +160,6 @@
|
||||||
//! # else {
|
//! # else {
|
||||||
//! # unreachable!();
|
//! # unreachable!();
|
||||||
//! # }
|
//! # }
|
||||||
//! }
|
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
#![deny(
|
#![deny(
|
||||||
|
@ -266,10 +261,8 @@ impl<T: 'static + Display + Debug> ChainError<T> {
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// fn main() {
|
|
||||||
/// if let Err(e) = func1() {
|
/// if let Err(e) = func1() {
|
||||||
/// if let Some(f1err) = e.downcast_chain_ref::<Func1Error>() {
|
/// if let Some(f1err) = e.downcast_chain_ref::<Func1Error>() {
|
||||||
///
|
|
||||||
/// assert!(f1err.find_cause::<io::Error>().is_some());
|
/// assert!(f1err.find_cause::<io::Error>().is_some());
|
||||||
///
|
///
|
||||||
/// assert!(f1err.find_chain_cause::<Func2Error>().is_some());
|
/// assert!(f1err.find_chain_cause::<Func2Error>().is_some());
|
||||||
|
@ -281,7 +274,6 @@ impl<T: 'static + Display + Debug> ChainError<T> {
|
||||||
/// # else {
|
/// # else {
|
||||||
/// # unreachable!();
|
/// # unreachable!();
|
||||||
/// # }
|
/// # }
|
||||||
/// }
|
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn find_cause<U: Error + 'static>(&self) -> Option<&U> {
|
pub fn find_cause<U: Error + 'static>(&self) -> Option<&U> {
|
||||||
|
@ -386,7 +378,6 @@ impl<T: 'static + Display + Debug> ChainError<T> {
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// fn main() {
|
|
||||||
/// if let Err(e) = func1() {
|
/// if let Err(e) = func1() {
|
||||||
/// match e.kind() {
|
/// match e.kind() {
|
||||||
/// Func1ErrorKind::Func2 => {}
|
/// Func1ErrorKind::Func2 => {}
|
||||||
|
@ -396,7 +387,6 @@ impl<T: 'static + Display + Debug> ChainError<T> {
|
||||||
/// # else {
|
/// # else {
|
||||||
/// # unreachable!();
|
/// # unreachable!();
|
||||||
/// # }
|
/// # }
|
||||||
/// }
|
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn kind(&self) -> &T {
|
pub fn kind(&self) -> &T {
|
||||||
|
@ -406,8 +396,6 @@ impl<T: 'static + Display + Debug> ChainError<T> {
|
||||||
/// Returns an Iterator over all error causes/sources
|
/// Returns an Iterator over all error causes/sources
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
///
|
|
||||||
///
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn iter(&self) -> impl Iterator<Item = &(dyn Error + 'static)> {
|
pub fn iter(&self) -> impl Iterator<Item = &(dyn Error + 'static)> {
|
||||||
ErrorIter {
|
ErrorIter {
|
||||||
|
@ -769,17 +757,15 @@ macro_rules! minto_cherr {
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// fn func() -> ChainResult<(), FooError> {
|
/// fn func() -> ChainResult<(), FooError> {
|
||||||
/// if ! do_some_stuff() {
|
/// if !do_some_stuff() {
|
||||||
/// Err(cherr!(FooError::Baz("Error")))?;
|
/// Err(cherr!(FooError::Baz("Error")))?;
|
||||||
/// }
|
/// }
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
/// # pub fn main() {
|
|
||||||
/// # match func().unwrap_err().kind() {
|
/// # match func().unwrap_err().kind() {
|
||||||
/// # FooError::Baz(s) if s == &"Error" => {}
|
/// # FooError::Baz(s) if s == &"Error" => {}
|
||||||
/// # _ => panic!(),
|
/// # _ => panic!(),
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// Additionally an error cause can be added.
|
/// Additionally an error cause can be added.
|
||||||
|
@ -807,17 +793,13 @@ macro_rules! minto_cherr {
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// fn func() -> ChainResult<(), FooError> {
|
/// fn func() -> ChainResult<(), FooError> {
|
||||||
/// do_some_stuff().map_err(
|
/// do_some_stuff().map_err(|e| cherr!(e, FooError::Baz("Error")))?;
|
||||||
/// |e| cherr!(e, FooError::Baz("Error"))
|
|
||||||
/// )?;
|
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
/// # pub fn main() {
|
|
||||||
/// # match func().unwrap_err().kind() {
|
/// # match func().unwrap_err().kind() {
|
||||||
/// # FooError::Baz(s) if s == &"Error" => {}
|
/// # FooError::Baz(s) if s == &"Error" => {}
|
||||||
/// # _ => panic!(),
|
/// # _ => panic!(),
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! cherr {
|
macro_rules! cherr {
|
||||||
|
@ -865,14 +847,13 @@ macro_rules! cherr {
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// # fn main() {
|
|
||||||
/// # if let Err(e) = func1() {
|
/// # if let Err(e) = func1() {
|
||||||
/// # #[cfg(not(windows))]
|
/// # #[cfg(not(windows))]
|
||||||
/// # assert_eq!(
|
/// # assert_eq!(
|
||||||
/// # format!("\n{:?}\n", e), r#"
|
/// # format!("\n{:?}\n", e), r#"
|
||||||
/// # src/lib.rs:18: func1 error
|
/// # src/lib.rs:19: func1 error
|
||||||
/// # Caused by:
|
/// # Caused by:
|
||||||
/// # src/lib.rs:13: Error reading 'foo.txt'
|
/// # src/lib.rs:14: Error reading 'foo.txt'
|
||||||
/// # Caused by:
|
/// # Caused by:
|
||||||
/// # Kind(NotFound)
|
/// # Kind(NotFound)
|
||||||
/// # "#
|
/// # "#
|
||||||
|
@ -880,7 +861,6 @@ macro_rules! cherr {
|
||||||
/// # } else {
|
/// # } else {
|
||||||
/// # unreachable!();
|
/// # unreachable!();
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// `mstrerr!()` can also be used to map a new `ChainError<T>`, where T was defined with
|
/// `mstrerr!()` can also be used to map a new `ChainError<T>`, where T was defined with
|
||||||
|
@ -909,7 +889,6 @@ macro_rules! cherr {
|
||||||
/// func2().map_err(mstrerr!(Func1Error, "func1 error"))?;
|
/// func2().map_err(mstrerr!(Func1Error, "func1 error"))?;
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
/// # fn main() {
|
|
||||||
/// # if let Err(e) = func1() {
|
/// # if let Err(e) = func1() {
|
||||||
/// # if let Some(f1err) = e.downcast_chain_ref::<Func1Error>() {
|
/// # if let Some(f1err) = e.downcast_chain_ref::<Func1Error>() {
|
||||||
/// # assert!(f1err.find_cause::<ChainError<Func2Error>>().is_some());
|
/// # assert!(f1err.find_cause::<ChainError<Func2Error>>().is_some());
|
||||||
|
@ -920,7 +899,6 @@ macro_rules! cherr {
|
||||||
/// # } else {
|
/// # } else {
|
||||||
/// # unreachable!();
|
/// # unreachable!();
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! mstrerr {
|
macro_rules! mstrerr {
|
||||||
|
@ -965,7 +943,6 @@ macro_rules! mstrerr {
|
||||||
/// func2().map_err(mstrerr!(Func1Error, "func1 error"))?;
|
/// func2().map_err(mstrerr!(Func1Error, "func1 error"))?;
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
/// # fn main() {
|
|
||||||
/// # if let Err(e) = func1() {
|
/// # if let Err(e) = func1() {
|
||||||
/// # if let Some(f1err) = e.downcast_chain_ref::<Func1Error>() {
|
/// # if let Some(f1err) = e.downcast_chain_ref::<Func1Error>() {
|
||||||
/// # assert!(f1err.find_cause::<ChainError<Func2Error>>().is_some());
|
/// # assert!(f1err.find_cause::<ChainError<Func2Error>>().is_some());
|
||||||
|
@ -976,7 +953,6 @@ macro_rules! mstrerr {
|
||||||
/// # } else {
|
/// # } else {
|
||||||
/// # unreachable!();
|
/// # unreachable!();
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! strerr {
|
macro_rules! strerr {
|
||||||
|
@ -1027,7 +1003,6 @@ macro_rules! strerr {
|
||||||
/// func2().map_err(mstrerr!(Func1Error, "func1 error"))?;
|
/// func2().map_err(mstrerr!(Func1Error, "func1 error"))?;
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
/// # fn main() {
|
|
||||||
/// # if let Err(e) = func1() {
|
/// # if let Err(e) = func1() {
|
||||||
/// # if let Some(f1err) = e.downcast_chain_ref::<Func1Error>() {
|
/// # if let Some(f1err) = e.downcast_chain_ref::<Func1Error>() {
|
||||||
/// # assert!(f1err.find_cause::<ChainError<Func2Error>>().is_some());
|
/// # assert!(f1err.find_cause::<ChainError<Func2Error>>().is_some());
|
||||||
|
@ -1038,7 +1013,6 @@ macro_rules! strerr {
|
||||||
/// # } else {
|
/// # } else {
|
||||||
/// # unreachable!();
|
/// # unreachable!();
|
||||||
/// # }
|
/// # }
|
||||||
/// # }
|
|
||||||
/// ```
|
/// ```
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! derive_str_cherr {
|
macro_rules! derive_str_cherr {
|
||||||
|
@ -1070,8 +1044,8 @@ macro_rules! derive_str_cherr {
|
||||||
/// # Examples
|
/// # Examples
|
||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use std::io;
|
|
||||||
/// use chainerror::*;
|
/// use chainerror::*;
|
||||||
|
/// use std::io;
|
||||||
///
|
///
|
||||||
/// fn do_some_io(_f: &str) -> std::result::Result<(), io::Error> {
|
/// fn do_some_io(_f: &str) -> std::result::Result<(), io::Error> {
|
||||||
/// return Err(io::Error::from(io::ErrorKind::NotFound));
|
/// return Err(io::Error::from(io::ErrorKind::NotFound));
|
||||||
|
|
Loading…
Reference in a new issue