Skip to content

Commit b84c50f

Browse files
committed
---
yaml --- r: 262143 b: refs/heads/snap-stage3 c: 5f20143 h: refs/heads/master i: 262141: b148741 262139: e526dd9 262135: a52374e 262127: ebafa31 262111: 6423202 262079: 35ab85a 262015: 08efe02 261887: 57ba2d8 261631: 335db1c 261119: e72a428 260095: 1f26b4a 258047: a2e9a59 253951: 94e831b 245759: 142ab2f 229375: 1543e46 196607: 8d8c63c 131071: 126dbf5
1 parent 2ec8f4b commit b84c50f

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 5a0308abadce38396f27122d5c8639ffb2a21469
3-
refs/heads/snap-stage3: 25d068e36ed2f4c1b526185fbb2763c38616a10f
3+
refs/heads/snap-stage3: 5f20143ccfd1a74a8a104ecac33f777ade12992f
44
refs/heads/try: 29d24a3b02cb805da19450bf9830a8f0a6bd859c
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/snap-stage3/src/doc/book/error-handling.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,18 @@ fn file_path_ext(file_path: &str) -> Option<&str> {
359359
}
360360
```
361361

362-
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>>`.
362+
The `map` function here wraps the value returned by the `extension` function
363+
inside an `Option<_>` and since the `extension` function itself returns an
364+
`Option<&str>` the expression `file_name(file_path).map(|x| extension(x))`
365+
actually returns an `Option<Option<&str>>`.
363366

364-
But since `file_path_ext` just returns `Option<&str>` (and not `Option<Option<&str>>`) we get a compilation error.
367+
But since `file_path_ext` just returns `Option<&str>` (and not
368+
`Option<Option<&str>>`) we get a compilation error.
365369

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

368375
Its generic implementation is even simpler than `map`:
369376

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

390-
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.
397+
Side note: Since `and_then` essentially works like `map` but returns an
398+
`Option<_>` instead of an `Option<Option<_>>` it is known as `flatmap` in some
399+
other languages.
391400

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

0 commit comments

Comments
 (0)