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
//! Functions for unwrapping [`Result`]s
/// # Safety
/// The matchee must be passed by value
/// Const version of [`Result::expect`] without the [`Debug`] formatting.
///
/// Can also be used in combination with [`Result::is_ok`] to match the result.
///
/// # Example
/// ```
/// use const_util::result::expect_ok;
/// const fn double<E>(res: Result<i32, E>) -> Result<i32, E> {
/// if res.is_ok() {
/// Ok(2 * expect_ok(res, "Unreachable"))
/// } else {
/// res
/// }
/// }
/// assert_eq!(double(Ok::<_, String>(1)), Ok(2));
/// ```
pub const
/// Const version of [`Result::unwrap`] without the [`Debug`] formatting.
///
/// Can also be used in combination with [`Result::is_ok`] to match the result.
///
/// # Example
/// ```
/// use const_util::result::unwrap_ok;
/// const fn double<E>(res: Result<i32, E>) -> Result<i32, E> {
/// if res.is_ok() {
/// Ok(2 * unwrap_ok(res))
/// } else {
/// res
/// }
/// }
/// assert_eq!(double(Ok::<_, String>(1)), Ok(2));
/// ```
pub const
/// Const version of [`Result::expect_err`] without the [`Debug`] formatting.
///
/// Can also be used in combination with [`Result::is_err`] to match the result.
///
/// # Example
/// ```
/// use const_util::result::expect_err;
/// const fn double<T>(res: Result<T, i32>) -> Result<T, i32> {
/// if res.is_err() {
/// Err(2 * expect_err(res, "Unreachable"))
/// } else {
/// res
/// }
/// }
/// assert_eq!(double(Err::<String, _>(1)), Err(2));
/// ```
pub const
/// Const version of [`Result::unwrap_err`] without the [`Debug`] formatting.
///
/// Can also be used in combination with [`Result::is_err`] to match the result.
///
/// # Example
/// ```
/// use const_util::result::unwrap_err;
/// const fn double<T>(res: Result<T, i32>) -> Result<T, i32> {
/// if res.is_err() {
/// Err(2 * unwrap_err(res))
/// } else {
/// res
/// }
/// }
/// assert_eq!(double(Err::<String, _>(1)), Err(2));
/// ```
pub const