Skip to content

Commit 8bf8cbb

Browse files
committed
Auto merge of #162 - c-rustacean:rustfmt-and-ws-fixes, r=komaeda
errorsn.rs: Separate also the hints from each other to avoid accidental viewing
2 parents fffbb60 + f507844 commit 8bf8cbb

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

exercises/error_handling/errorsn.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,49 @@ impl error::Error for CreationError {
146146
// `read_and_validate` returns and`test_with_str` has its signature fully
147147
// specified.
148148

149+
150+
151+
152+
153+
154+
155+
156+
157+
158+
159+
160+
161+
162+
163+
164+
165+
166+
167+
149168
// Next hint: There are three places in `read_and_validate` that we call a
150169
// function that returns a `Result` (that is, the functions might fail).
151170
// Apply the `?` operator on those calls so that we return immediately from
152171
// `read_and_validate` if those function calls fail.
153172

173+
174+
175+
176+
177+
178+
179+
180+
181+
182+
183+
184+
185+
186+
187+
188+
189+
190+
191+
154192
// Another hint: under the hood, the `?` operator calls `From::from`
155193
// on the error value to convert it to a boxed trait object, a Box<error::Error>,
156194
// which is polymorphic-- that means that lots of different kinds of errors
@@ -159,12 +197,50 @@ impl error::Error for CreationError {
159197
// Check out this section of the book:
160198
// https://doc.rust-lang.org/stable/book/second-edition/ch09-02-recoverable-errors-with-result.html#a-shortcut-for-propagating-errors-the--operator
161199

200+
201+
202+
203+
204+
205+
206+
207+
208+
209+
210+
211+
212+
213+
214+
215+
216+
217+
218+
162219
// Another another hint: Note that because the `?` operator returns
163220
// the *unwrapped* value in the `Ok` case, if we want to return a `Result` from
164221
// `read_and_validate` for *its* success case, we'll have to rewrap a value
165222
// that we got from the return value of a `?`ed call in an `Ok`-- this will
166223
// look like `Ok(something)`.
167224

225+
226+
227+
228+
229+
230+
231+
232+
233+
234+
235+
236+
237+
238+
239+
240+
241+
242+
243+
168244
// Another another another hint: `Result`s must be "used", that is, you'll
169245
// get a warning if you don't handle a `Result` that you get in your
170246
// function. Read more about that in the `std::result` module docs:

0 commit comments

Comments
 (0)