Skip to content

Commit

Permalink
refine readme examples
Browse files Browse the repository at this point in the history
Signed-off-by: Bugen Zhao <[email protected]>
  • Loading branch information
BugenZhao committed Dec 7, 2023
1 parent 022b14e commit 801260f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,26 @@ enum ErrorKind {
NotImplemented {
issue: Option<i32>,
#[message] msg: String,
}
},

#[error("internal error: {0}")]
Internal(String),
}

// `thiserror_ext::Construct`
let error: Error = Error::internal("oops");

// `thiserror_ext::Box`
assert_eq!(std::mem::size_of::<Error>(), std::mem::size_of::<usize>());
let _: &Backtrace = std::error::request_ref(&error).unwrap();

// `thiserror_ext::Construct`
let _: Error = Error::internal("oops");
let bt: &Backtrace = std::error::request_ref(&error).unwrap();

// `thiserror_ext::ContextInto`
let _: Result<i32, Error> = "foo".parse::<i32>().into_parse("foo");
let result: Result<i32, Error> = "foo".parse().into_parse("foo");

// `thiserror_ext::AsReport`
//
// "cannot parse int from `foo`: invalid digit found in string"
println!("{}", result.unwrap_err().as_report());

// `thiserror_ext::Macro`
bail_not_implemented!(issue = 42, "an {} feature", "awesome");
Expand Down

0 comments on commit 801260f

Please sign in to comment.