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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
use ;
use crate::;
/// A basic error type that you can use as a first step to better
/// error handling.
///
/// You can use this type in your own application as a quick way to
/// create errors or add basic context to another error. This can also
/// be used in a library, but consider wrapping it in an
/// [opaque](crate::guide::opaque) error to avoid putting the SNAFU
/// crate in your public API.
///
/// ## Examples
///
/// ```rust
/// use snafu::prelude::*;
///
/// type Result<T, E = snafu::Whatever> = std::result::Result<T, E>;
///
/// fn subtract_numbers(a: u32, b: u32) -> Result<u32> {
/// if a > b {
/// Ok(a - b)
/// } else {
/// whatever!("Can't subtract {a} - {b}")
/// }
/// }
///
/// fn complicated_math(a: u32, b: u32) -> Result<u32> {
/// let val = subtract_numbers(a, b).whatever_context("Can't do the math")?;
/// Ok(val * 2)
/// }
/// ```
///
/// See [`whatever!`][crate::whatever!] for detailed usage instructions.
///
/// ## Limitations
///
/// When wrapping errors, only the backtrace from the shallowest
/// function is guaranteed to be available. If you need the deepest
/// possible trace, consider creating a custom error type and [using
/// `#[snafu(backtrace)]` on the `source`
/// field](Snafu#controlling-backtraces). If a best-effort attempt is
/// sufficient, see the [`backtrace`][Self::backtrace] method.
///
/// When the standard library stabilizes support for the
/// [provide API](https://doc.rust-lang.org/std/error/trait.Error.html#method.provide),
/// this behavior may change.
///
/// ## Thread Safety
///
/// This type requires that contained errors implement [`Send`][] and
/// [`Sync`][]. If this is burdensome, you may also use
/// [`WhateverLocal`][].
/// A basic error type that you can use as a first step to better
/// error handling when the error does not need to cross a thread
/// boundary.
///
/// This type behaves the same as [`Whatever`][] except it does not
/// require that the wrapped errors implement [`Send`][] or
/// [`Sync`][]. See [`Whatever`][] and [`whatever!`][crate::whatever!] for detailed
/// usage instructions.