Skip to content

Commit cf0f7a3

Browse files
committed
Rollup merge of rust-lang#31295 - steveklabnik:gh31266, r=alexcrichton
These are free functions in the text, but methods in the standard library. Fixes rust-lang#31266
2 parents ee7670e + a2c3286 commit cf0f7a3

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Diff for: src/doc/book/error-handling.md

+5
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,8 @@ fn map<F, T, A>(option: Option<T>, f: F) -> Option<A> where F: FnOnce(T) -> A {
265265
```
266266

267267
Indeed, `map` is [defined as a method][2] on `Option<T>` in the standard library.
268+
As a method, it has a slighly different signature: methods take `self`, `&self`,
269+
or `&mut self` as their first argument.
268270

269271
Armed with our new combinator, we can rewrite our `extension_explicit` method
270272
to get rid of the case analysis:
@@ -294,6 +296,9 @@ fn unwrap_or<T>(option: Option<T>, default: T) -> T {
294296
}
295297
```
296298

299+
Like with `map` above, the standard library implementation is a method instead
300+
of a free function.
301+
297302
The trick here is that the default value must have the same type as the value
298303
that might be inside the `Option<T>`. Using it is dead simple in our case:
299304

0 commit comments

Comments
 (0)