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