@@ -146,11 +146,49 @@ impl error::Error for CreationError {
146
146
// `read_and_validate` returns and`test_with_str` has its signature fully
147
147
// specified.
148
148
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
149
168
// Next hint: There are three places in `read_and_validate` that we call a
150
169
// function that returns a `Result` (that is, the functions might fail).
151
170
// Apply the `?` operator on those calls so that we return immediately from
152
171
// `read_and_validate` if those function calls fail.
153
172
173
+
174
+
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
154
192
// Another hint: under the hood, the `?` operator calls `From::from`
155
193
// on the error value to convert it to a boxed trait object, a Box<error::Error>,
156
194
// which is polymorphic-- that means that lots of different kinds of errors
@@ -159,12 +197,50 @@ impl error::Error for CreationError {
159
197
// Check out this section of the book:
160
198
// https://doc.rust-lang.org/stable/book/second-edition/ch09-02-recoverable-errors-with-result.html#a-shortcut-for-propagating-errors-the--operator
161
199
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
162
219
// Another another hint: Note that because the `?` operator returns
163
220
// the *unwrapped* value in the `Ok` case, if we want to return a `Result` from
164
221
// `read_and_validate` for *its* success case, we'll have to rewrap a value
165
222
// that we got from the return value of a `?`ed call in an `Ok`-- this will
166
223
// look like `Ok(something)`.
167
224
225
+
226
+
227
+
228
+
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
168
244
// Another another another hint: `Result`s must be "used", that is, you'll
169
245
// get a warning if you don't handle a `Result` that you get in your
170
246
// function. Read more about that in the `std::result` module docs:
0 commit comments