|
13 | 13 | // type goes where the question marks are, and how do we return |
14 | 14 | // that type from the body of read_and_validate? |
15 | 15 | // |
16 | | -// Scroll down for hints :) |
| 16 | +// Execute `rustlings hint errors4` for hints :) |
17 | 17 |
|
18 | 18 | use std::error; |
19 | 19 | use std::fmt; |
@@ -110,138 +110,3 @@ impl error::Error for CreationError { |
110 | 110 | } |
111 | 111 | } |
112 | 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 | | -// First hint: To figure out what type should go where the ??? is, take a look |
145 | | -// at the test helper function `test_with_str`, since it returns whatever |
146 | | -// `read_and_validate` returns and`test_with_str` has its signature fully |
147 | | -// specified. |
148 | | - |
149 | | - |
150 | | - |
151 | | - |
152 | | - |
153 | | - |
154 | | - |
155 | | - |
156 | | - |
157 | | - |
158 | | - |
159 | | - |
160 | | - |
161 | | - |
162 | | - |
163 | | - |
164 | | - |
165 | | - |
166 | | - |
167 | | - |
168 | | -// Next hint: There are three places in `read_and_validate` that we call a |
169 | | -// function that returns a `Result` (that is, the functions might fail). |
170 | | -// Apply the `?` operator on those calls so that we return immediately from |
171 | | -// `read_and_validate` if those function calls fail. |
172 | | - |
173 | | - |
174 | | - |
175 | | - |
176 | | - |
177 | | - |
178 | | - |
179 | | - |
180 | | - |
181 | | - |
182 | | - |
183 | | - |
184 | | - |
185 | | - |
186 | | - |
187 | | - |
188 | | - |
189 | | - |
190 | | - |
191 | | - |
192 | | -// Another hint: under the hood, the `?` operator calls `From::from` |
193 | | -// on the error value to convert it to a boxed trait object, a Box<dyn error::Error>, |
194 | | -// which is polymorphic-- that means that lots of different kinds of errors |
195 | | -// can be returned from the same function because all errors act the same |
196 | | -// since they all implement the `error::Error` trait. |
197 | | -// Check out this section of the book: |
198 | | -// https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html#a-shortcut-for-propagating-errors-the--operator |
199 | | - |
200 | | - |
201 | | - |
202 | | - |
203 | | - |
204 | | - |
205 | | - |
206 | | - |
207 | | - |
208 | | - |
209 | | - |
210 | | - |
211 | | - |
212 | | - |
213 | | - |
214 | | - |
215 | | - |
216 | | - |
217 | | - |
218 | | - |
219 | | -// Another another hint: Note that because the `?` operator returns |
220 | | -// the *unwrapped* value in the `Ok` case, if we want to return a `Result` from |
221 | | -// `read_and_validate` for *its* success case, we'll have to rewrap a value |
222 | | -// that we got from the return value of a `?`ed call in an `Ok`-- this will |
223 | | -// look like `Ok(something)`. |
224 | | - |
225 | | - |
226 | | - |
227 | | - |
228 | | - |
229 | | - |
230 | | - |
231 | | - |
232 | | - |
233 | | - |
234 | | - |
235 | | - |
236 | | - |
237 | | - |
238 | | - |
239 | | - |
240 | | - |
241 | | - |
242 | | - |
243 | | - |
244 | | -// Another another another hint: `Result`s must be "used", that is, you'll |
245 | | -// get a warning if you don't handle a `Result` that you get in your |
246 | | -// function. Read more about that in the `std::result` module docs: |
247 | | -// https://doc.rust-lang.org/std/result/#results-must-be-used |
0 commit comments