maybe_unwind/lib.rs
1/*!
2A wrapper of [`catch_unwind`] that also captures the panic information.
3
4The main purpose of this library is to provide a utility for capturing
5the error information from assetion macros in custom test libraries.
6
7[`catch_unwind`]: https://doc.rust-lang.org/stable/std/panic/fn.catch_unwind.html
8
9# Example
10
11```
12use maybe_unwind::maybe_unwind;
13
14std::panic::set_hook(Box::new(|info| {
15 maybe_unwind::capture_panic_info(info);
16}));
17
18if let Err(unwind) = maybe_unwind(|| do_something()) {
19 eprintln!("payload = {:?}", unwind.payload());
20 eprintln!("location = {:?}", unwind.location());
21}
22# fn do_something() {}
23```
24!*/
25
26#![doc(html_root_url = "https://docs.rs/maybe-unwind/0.3.1")]
27#![deny(missing_docs)]
28#![forbid(clippy::todo, clippy::unimplemented)]
29#![cfg_attr(backtrace, feature(backtrace))]
30#![cfg_attr(docs, feature(doc_cfg))]
31
32#[macro_use]
33mod backtrace;
34#[macro_use]
35mod context;
36mod hook;
37mod unwind;
38
39pub use crate::{
40 hook::capture_panic_info,
41 unwind::{maybe_unwind, Location, Unwind},
42};
43
44#[cfg(feature = "futures")]
45mod futures;
46
47#[cfg(feature = "futures")]
48pub use futures::{FutureMaybeUnwindExt, MaybeUnwind};