Skip to content

Make note that this is different in std #31295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/doc/book/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:

Expand Down