@@ -112,7 +112,7 @@ mod prim_bool { }
112
112
///
113
113
/// # `!` and generics
114
114
///
115
- /// ## Infalliable errors
115
+ /// ## Infallible errors
116
116
///
117
117
/// The main place you'll see `!` used explicitly is in generic code. Consider the [`FromStr`]
118
118
/// trait:
@@ -144,7 +144,7 @@ mod prim_bool { }
144
144
///
145
145
/// ## Infinite loops
146
146
///
147
- /// While [`Result<T, !>`] is very useful for removing errors, `!` can also be used to removed
147
+ /// While [`Result<T, !>`] is very useful for removing errors, `!` can also be used to remove
148
148
/// successes as well. If we think of [`Result<T, !>`] as "if this function returns, it has not
149
149
/// errored," we get a very intuitive idea of [`Result<!, E>`] as well: if the function returns, it
150
150
/// *has* errored.
@@ -175,21 +175,22 @@ mod prim_bool { }
175
175
/// ```
176
176
///
177
177
/// Now, when the server disconnects, we exit the loop with an error instead of panicking. While it
178
- /// might be intuitive to simply return the error, we might want to wrap it in a [`Result<!, E>`]
178
+ /// might be intuitive to simply return the error, we might want to wrap it in a [`Result<!, E>`]
179
179
/// instead:
180
180
///
181
181
/// ```ignore (hypothetical-example)
182
182
/// fn server_loop() -> Result<!, ConnectionError> {
183
- /// Ok( loop {
183
+ /// loop {
184
184
/// let (client, request) = get_request()?;
185
185
/// let response = request.process();
186
186
/// response.send(client);
187
- /// })
187
+ /// }
188
188
/// }
189
189
/// ```
190
190
///
191
191
/// Now, we can use `?` instead of `match`, and the return type makes a lot more sense: if the loop
192
- /// ever stops, it means that an error occurred.
192
+ /// ever stops, it means that an error occurred. We don't even have to wrap the loop in an `Ok`
193
+ /// because `!` coerces to `Result<!, ConnectionError>` automatically.
193
194
///
194
195
/// [`String::from_str`]: str/trait.FromStr.html#tymethod.from_str
195
196
/// [`Result<String, !>`]: result/enum.Result.html
0 commit comments