Skip to content

Commit a2c3286

Browse files
committed
Make note that this is different in std
These are free functions in the text, but methods in the standard library. Fixes rust-lang#31266
1 parent 552bf75 commit a2c3286

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/doc/book/error-handling.md

Lines changed: 5 additions & 0 deletions
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)