1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use crate::;
use PanicInfo;
/// Capture the panic information.
///
/// The captured values are stored in the thread local context
/// for passing to the caller of `maybe_unwind`. After capturing
/// the panic information, this function returns `true`.
///
/// If the panic location is outside of the closure passed to
/// `maybe_unwind`, this function does nothing and just return
/// `false`.
///
/// # Example
///
/// ```
/// use maybe_unwind::{maybe_unwind, capture_panic_info};
/// use std::panic::{self, PanicInfo};
///
/// fn my_hook(info: &PanicInfo) {
/// let captured = capture_panic_info(info);
///
/// if !captured {
/// println!("{}", info);
/// }
/// }
/// panic::set_hook(Box::new(my_hook));
///
/// let res = maybe_unwind(|| { panic!("oops"); });
/// assert!(res.is_err());
/// ```