diff options
| author | Manish Goregaokar <manishsmail@gmail.com> | 2016-01-30 17:57:17 +0530 |
|---|---|---|
| committer | Manish Goregaokar <manishsmail@gmail.com> | 2016-01-30 17:57:17 +0530 |
| commit | cf0f7a30f460503d3cb11cf26a03561d225f852d (patch) | |
| tree | 41f42319ae8243fe6529f777a0681687b6305af4 | |
| parent | ee7670ef345b880187cecde122c276541424bb8c (diff) | |
| parent | a2c328661b3be61ead155d887efd001c13c794ad (diff) | |
| download | rust-cf0f7a30f460503d3cb11cf26a03561d225f852d.tar.gz rust-cf0f7a30f460503d3cb11cf26a03561d225f852d.zip | |
Rollup merge of #31295 - steveklabnik:gh31266, r=alexcrichton
These are free functions in the text, but methods in the standard library. Fixes #31266
| -rw-r--r-- | src/doc/book/error-handling.md | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/doc/book/error-handling.md b/src/doc/book/error-handling.md index 40891dbe191..78527c21d10 100644 --- a/src/doc/book/error-handling.md +++ b/src/doc/book/error-handling.md @@ -265,6 +265,8 @@ fn map<F, T, A>(option: Option<T>, f: F) -> Option<A> where F: FnOnce(T) -> A { ``` Indeed, `map` is [defined as a method][2] on `Option<T>` in the standard library. +As a method, it has a slighly different signature: methods take `self`, `&self`, +or `&mut self` as their first argument. Armed with our new combinator, we can rewrite our `extension_explicit` method to get rid of the case analysis: @@ -294,6 +296,9 @@ fn unwrap_or<T>(option: Option<T>, default: T) -> T { } ``` +Like with `map` above, the standard library implementation is a method instead +of a free function. + The trick here is that the default value must have the same type as the value that might be inside the `Option<T>`. Using it is dead simple in our case: |
