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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
use Infallible;
use crate;
use crate;
use FailureFormat;
/// A formatter for matchers that never fail.
///
/// This formatter doesn't actually format anything, because it can never be called. It is mostly
/// useful for matchers like [`MapMatcher`] that can never fail.
;
/// Infallibly map the input value by applying a function to it.
///
/// This does the same thing as [`Assertion::map`].
///
/// This matcher always succeeds, even when negated. Therefore negating it has no effect.
///
/// # Examples
///
/// ```
/// use std::convert::Infallible;
/// use xpct::{expect, map, equal};
///
/// fn do_stuff() -> Result<String, Infallible> {
/// Ok(String::from("foobar"))
/// }
///
/// expect!(do_stuff())
/// .to(map(Result::unwrap))
/// .to(equal("foobar"));
/// ```
///
/// [`Assertion::map`]: crate::core::Assertion::map
/// Fallibly map the input value by applying a function to it.
///
/// This does the same thing as [`Assertion::try_map`].
///
/// This matcher always succeeds as long as `func` returns `Ok`, even when negated. Therefore
/// negating it has no effect.
///
/// # Examples
///
/// ```
/// use xpct::{expect, equal, try_map};
///
/// expect!(vec![0x43, 0x75, 0x6e, 0x6f])
/// .to(try_map(|bytes| Ok(String::from_utf8(bytes)?)))
/// .to(equal("Cuno"));
/// ```
///
/// [`Assertion::try_map`]: crate::core::Assertion::map
/// Infallibly convert the input value via [`From`]/[`Into`].
///
/// This does the same thing as [`Assertion::into`].
///
/// This matcher always succeeds, even when negated. Therefore negating it has no effect.
///
/// # Examples
///
/// ```
/// use xpct::{expect, equal, into};
///
/// expect!(41u32)
/// .to(into::<_, u64>())
/// .to(equal(41u64));
/// ```
///
/// [`Assertion::into`]: crate::core::Assertion::into
/// Fallibly convert the input value via [`TryFrom`]/[`TryInto`].
///
/// This does the same thing as [`Assertion::try_into`].
///
/// This matcher always succeeds as long as [`TryFrom::try_from`] returns `Ok`, even when negated.
/// Therefore negating it has no effect.
///
/// # Examples
///
/// ```
/// use xpct::{expect, equal, try_into};
///
/// expect!(41u64)
/// .to(try_into::<_, u32>())
/// .to(equal(41u32));
/// ```
///
/// [`Assertion::try_into`]: crate::core::Assertion::try_into
/// Infallibly map each value of an iterator by applying a function to it.
///
/// This does the same thing as [`Assertion::iter_map`].
///
/// This matcher always succeeds, even when negated. Therefore negating it has no effect.
///
/// # Examples
///
/// ```
/// use xpct::{be_some, every, expect, iter_map};
///
/// let items = vec![Some("foo"), Some("bar")];
///
/// let output: Vec<&str> = expect!(&items)
/// .to(iter_map(Option::as_deref))
/// .to(every(be_some))
/// .into_inner();
/// ```
///
/// [`Assertion::iter_map`]: crate::core::Assertion::iter_map
/// Fallibly map each value of an iterator by applying a function to it.
///
/// This does the same thing as [`Assertion::iter_try_map`].
///
/// This matcher always succeeds as long as `func` returns `Ok`, even when negated. Therefore
/// negating it has no effect.
///
/// # Examples
///
/// ```
/// use xpct::{expect, iter_try_map, consist_of};
///
/// let small_integers: [u64; 2] = [41, 57];
///
/// expect!(small_integers)
/// .to(iter_try_map(|value| Ok(u32::try_from(value)?)))
/// .to(consist_of([41u32, 57u32]));
/// ```
///
/// [`Assertion::iter_try_map`]: crate::core::Assertion::iter_try_map