Skip to content
This repository was archived by the owner on Aug 16, 2021. It is now read-only.

Made the simple example even simpler since the error as cause example… #311

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 3 additions & 15 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
#[macro_use]
extern crate failure;

use failure::Fail;

#[derive(Debug, Fail)]
#[fail(display = "my error")]
#[fail(display = "Hello World")]
struct MyError;

#[derive(Debug, Fail)]
#[fail(display = "my wrapping error")]
struct WrappingError(#[fail(cause)] MyError);

fn bad_function() -> Result<(), WrappingError> {
Err(WrappingError(MyError))
}

fn main() {
for cause in Fail::iter_chain(&bad_function().unwrap_err()) {
println!("{}: {}", cause.name().unwrap_or("Error"), cause);
}
let err: Result<(), MyError> = Err(MyError);
println!("{}", err.unwrap_err());
}