Skip to content

Rollup of 19 pull requests #31147

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

Closed
wants to merge 43 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
25d068e
Showed the difference between `map` and `and_then` with an example.
sandeep-datta Jan 17, 2016
0f8fc2c
Improve CStr::from_ptr example in docs
andreabedini Jan 19, 2016
9d77694
Fix type parameter default error to mention type and trait definitions
bluss Jan 18, 2016
796f158
Add test for #30123
brson Jan 19, 2016
ccba72e
Add examples of the Entry API to the HashMap documentation.
nathankleyn Jan 19, 2016
6849b6d
Remove leftover import of `std::str` in doc test
andreabedini Jan 19, 2016
a6778a2
Improve E0317 long diagnostics
Manishearth Jan 20, 2016
5f20143
Fixed line wrapping.
sandeep-datta Jan 20, 2016
132ec2c
Correct code in E0382 explanation
apasel422 Jan 20, 2016
6271ee9
tweak colors for a11y
steveklabnik Jan 20, 2016
5763b86
Add alt tags for logos
steveklabnik Jan 20, 2016
257a1ec
tweak struct colors
steveklabnik Jan 20, 2016
c449f04
tweak trait css
steveklabnik Jan 20, 2016
c158fd9
Add Alexis thesis to bibliography
brson Jan 20, 2016
52c89ee
doc: improve grammar
tshepang Jan 21, 2016
2a7bef6
doc: this sentence did not read well
tshepang Jan 21, 2016
48aa5ef
Fix typo in "Getting Started" section of the book
apasel422 Jan 22, 2016
c94b14a
update link to unwind in book
steveklabnik Jan 22, 2016
9624b68
book: Clarify that trait or type must be in same crate as impl
kamalmarhubi Jan 22, 2016
a559577
Forward reference crates and modules chapter
kamalmarhubi Jan 22, 2016
97f9cad
E0210: Add a warning about type aliases
marcbowes Jan 22, 2016
f81a11b
Document that BTreeMap iteration is in order
mbrubeck Jan 22, 2016
6a6e9a9
Fix the missing line in the guessing-game.md
vessd Jan 23, 2016
ac27ec2
Semaphore not sempahore
angelsl Jan 23, 2016
1201943
Rollup merge of #30971 - SDX2000:docfixes, r=steveklabnik
steveklabnik Jan 23, 2016
68e51c3
Rollup merge of #30997 - bluss:trait-default, r=nikomatsakis
steveklabnik Jan 23, 2016
4f00383
Rollup merge of #31019 - andreabedini:patch-1, r=alexcrichton
steveklabnik Jan 23, 2016
967bae4
Rollup merge of #31031 - brson:issue-30123, r=nikomatsakis
steveklabnik Jan 23, 2016
789701a
Rollup merge of #31035 - nathankleyn:improve-visibility-of-entry-api,…
steveklabnik Jan 23, 2016
01273f9
Rollup merge of #31045 - Manishearth:diag-prim-shadow, r=steveklabnik
steveklabnik Jan 23, 2016
2ff14a4
Rollup merge of #31050 - apasel422:issue-31048, r=Manishearth
steveklabnik Jan 23, 2016
cc92be6
Rollup merge of #31054 - steveklabnik:a11y, r=alexcrichton
steveklabnik Jan 23, 2016
fc51b68
Rollup merge of #31055 - steveklabnik:alt-tags, r=alexcrichton
steveklabnik Jan 23, 2016
0b40c6c
Rollup merge of #31061 - brson:bib, r=steveklabnik
steveklabnik Jan 23, 2016
bdd1507
Rollup merge of #31088 - tshepang:grammar, r=brson
steveklabnik Jan 23, 2016
9dfb4ac
Rollup merge of #31090 - tshepang:improve-sentence, r=brson
steveklabnik Jan 23, 2016
b026f7a
Rollup merge of #31111 - apasel422:issue-31103, r=steveklabnik
steveklabnik Jan 23, 2016
14f048d
Rollup merge of #31113 - steveklabnik:master, r=alexcrichton
steveklabnik Jan 23, 2016
b697b3e
Rollup merge of #31128 - kamalmarhubi:book-trait-impl-clarify, r=stev…
steveklabnik Jan 23, 2016
7c22c1a
Rollup merge of #31130 - marcbowes:master, r=nrc
steveklabnik Jan 23, 2016
96dbd8a
Rollup merge of #31136 - mbrubeck:btree-doc, r=steveklabnik
steveklabnik Jan 23, 2016
bd4c0b5
Rollup merge of #31145 - D101101:patch-1, r=steveklabnik
steveklabnik Jan 23, 2016
deefde0
Rollup merge of #31146 - angelsl:patch-1, r=steveklabnik
steveklabnik Jan 23, 2016
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
Prev Previous commit
Next Next commit
Fixed line wrapping.
  • Loading branch information
sandeep-datta committed Jan 20, 2016
commit 5f20143ccfd1a74a8a104ecac33f777ade12992f
17 changes: 13 additions & 4 deletions src/doc/book/error-handling.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,18 @@ fn file_path_ext(file_path: &str) -> Option<&str> {
}
```

The `map` function here wraps the value returned by the `extension` function inside an `Option<_>` and since the `extension` function itself returns an `Option<&str>` the expression `file_name(file_path).map(|x| extension(x))` actually returns an `Option<Option<&str>>`.
The `map` function here wraps the value returned by the `extension` function
inside an `Option<_>` and since the `extension` function itself returns an
`Option<&str>` the expression `file_name(file_path).map(|x| extension(x))`
actually returns an `Option<Option<&str>>`.

But since `file_path_ext` just returns `Option<&str>` (and not `Option<Option<&str>>`) we get a compilation error.
But since `file_path_ext` just returns `Option<&str>` (and not
`Option<Option<&str>>`) we get a compilation error.

The result of the function taken by map as input is *always* [rewrapped with `Some`](#code-option-map). Instead, we need something like `map`, but which allows the caller to return a `Option<_>` directly without wrapping it in another `Option<_>`.
The result of the function taken by map as input is *always* [rewrapped with
`Some`](#code-option-map). Instead, we need something like `map`, but which
allows the caller to return a `Option<_>` directly without wrapping it in
another `Option<_>`.

Its generic implementation is even simpler than `map`:

Expand All @@ -387,7 +394,9 @@ fn file_path_ext(file_path: &str) -> Option<&str> {
}
```

Side note: Since `and_then` essentially works like `map` but returns an `Option<_>` instead of an `Option<Option<_>>` it is known as `flatmap` in some other languages.
Side note: Since `and_then` essentially works like `map` but returns an
`Option<_>` instead of an `Option<Option<_>>` it is known as `flatmap` in some
other languages.

The `Option` type has many other combinators [defined in the standard
library][5]. It is a good idea to skim this list and familiarize
Expand Down