Skip to content

Commit 3a5e9a3

Browse files
committed
wrap more referenced code blocks in divs
1 parent 30c91cd commit 3a5e9a3

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/doc/trpl/error-handling.md

+14
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)