Skip to content

Commit a59743e

Browse files
committed
---
yaml --- r: 234724 b: refs/heads/tmp c: 3a5e9a3 h: refs/heads/master v: v3
1 parent 901cd31 commit a59743e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2626
refs/heads/beta: d2e13e822a73e0ea46ae9e21afdd3155fc997f6d
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
28-
refs/heads/tmp: 30c91cd7f7527cee89e4997827fbe61ea39f2729
28+
refs/heads/tmp: 3a5e9a3f9934a850753110769c49521a659cd03a
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: ab792abf1fcc28afbd315426213f6428da25c085
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828

branches/tmp/src/doc/trpl/error-handling.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ But wait, what about `unwrap` used in [`unwrap-double`](#code-unwrap-double)?
186186
There was no case analysis there! Instead, the case analysis was put inside the
187187
`unwrap` method for you. You could define it yourself if you want:
188188

189+
<div id="code-option-def-unwrap">
189190
```rust
190191
enum Option<T> {
191192
None,
@@ -202,6 +203,7 @@ impl<T> Option<T> {
202203
}
203204
}
204205
```
206+
</div>
205207

206208
The `unwrap` method *abstracts away the case analysis*. This is precisely the thing
207209
that makes `unwrap` ergonomic to use. Unfortunately, that `panic!` means that
@@ -251,6 +253,7 @@ option is `None`, in which case, just return `None`.
251253
Rust has parametric polymorphism, so it is very easy to define a combinator
252254
that abstracts this pattern:
253255

256+
<div id="code-option-map">
254257
```rust
255258
fn map<F, T, A>(option: Option<T>, f: F) -> Option<A> where F: FnOnce(T) -> A {
256259
match option {
@@ -259,6 +262,7 @@ fn map<F, T, A>(option: Option<T>, f: F) -> Option<A> where F: FnOnce(T) -> A {
259262
}
260263
}
261264
```
265+
</div>
262266

263267
Indeed, `map` is [defined as a method][2] on `Option<T>` in the standard library.
264268

@@ -390,12 +394,14 @@ remove choices because they will panic if `Option<T>` is `None`.
390394
The `Result` type is also
391395
[defined in the standard library][6]:
392396

397+
<div id="code-result-def-1">
393398
```rust
394399
enum Result<T, E> {
395400
Ok(T),
396401
Err(E),
397402
}
398403
```
404+
</div>
399405

400406
The `Result` type is a richer version of `Option`. Instead of expressing the
401407
possibility of *absence* like `Option` does, `Result` expresses the possibility
@@ -666,6 +672,7 @@ with both an `Option` and a `Result`, the solution is *usually* to convert the
666672
(from `env::args()`) means the user didn't invoke the program correctly. We
667673
could just use a `String` to describe the error. Let's try:
668674

675+
<div id="code-error-double-string">
669676
```rust
670677
use std::env;
671678

@@ -682,6 +689,7 @@ fn main() {
682689
}
683690
}
684691
```
692+
</div>
685693

686694
There are a couple new things in this example. The first is the use of the
687695
[`Option::ok_or`](../std/option/enum.Option.html#method.ok_or)
@@ -898,6 +906,7 @@ seen above.
898906

899907
Here is a simplified definition of a `try!` macro:
900908

909+
<div id="code-try-def-simple">
901910
```rust
902911
macro_rules! try {
903912
($e:expr) => (match $e {
@@ -906,6 +915,7 @@ macro_rules! try {
906915
});
907916
}
908917
```
918+
</div>
909919

910920
(The [real definition](../std/macro.try!.html) is a bit more
911921
sophisticated. We will address that later.)
@@ -1158,11 +1168,13 @@ The `std::convert::From` trait is
11581168
[defined in the standard
11591169
library](../std/convert/trait.From.html):
11601170

1171+
<div id="code-from-def">
11611172
```rust
11621173
trait From<T> {
11631174
fn from(T) -> Self;
11641175
}
11651176
```
1177+
</div>
11661178

11671179
Deliciously simple, yes? `From` is very useful because it gives us a generic
11681180
way to talk about conversion *from* a particular type `T` to some other type
@@ -1238,6 +1250,7 @@ macro_rules! try {
12381250
This is not it's real definition. It's real definition is
12391251
[in the standard library](../std/macro.try!.html):
12401252

1253+
<div id="code-try-def">
12411254
```rust
12421255
macro_rules! try {
12431256
($e:expr) => (match $e {
@@ -1246,6 +1259,7 @@ macro_rules! try {
12461259
});
12471260
}
12481261
```
1262+
</div>
12491263

12501264
There's one tiny but powerful change: the error value is passed through
12511265
`From::from`. This makes the `try!` macro a lot more powerful because it gives

0 commit comments

Comments
 (0)