@@ -24,28 +24,28 @@ systems may want to jump around.
24
24
* [ The Basics] ( #the-basics )
25
25
* [ Unwrapping explained] ( #unwrapping-explained )
26
26
* [ The ` Option ` type] ( #the-option-type )
27
- * [ Composing ` Option<T> ` values] ( #composing-option<t> -values )
27
+ * [ Composing ` Option<T> ` values] ( #composing-optiont -values )
28
28
* [ The ` Result ` type] ( #the-result-type )
29
29
* [ Parsing integers] ( #parsing-integers )
30
30
* [ The ` Result ` type alias idiom] ( #the-result-type-alias-idiom )
31
- * [ A brief interlude: unwrapping isn't evil] ( #a-brief-interlude: -unwrapping-isn't-evil )
31
+ * [ A brief interlude: unwrapping isn't evil] ( #a-brief-interlude-unwrapping-isn't-evil )
32
32
* [ Working with multiple error types] ( #working-with-multiple-error-types )
33
33
* [ Composing ` Option ` and ` Result ` ] ( #composing-option-and-result )
34
34
* [ The limits of combinators] ( #the-limits-of-combinators )
35
35
* [ Early returns] ( #early-returns )
36
- * [ The ` try! ` macro] ( #the-try! -macro )
36
+ * [ The ` try! ` macro] ( #the-try-macro )
37
37
* [ Defining your own error type] ( #defining-your-own-error-type )
38
38
* [ Standard library traits used for error handling] ( #standard-library-traits-used-for-error-handling )
39
39
* [ The ` Error ` trait] ( #the-error-trait )
40
40
* [ The ` From ` trait] ( #the-from-trait )
41
- * [ The real ` try! ` macro] ( #the-real-try! -macro )
41
+ * [ The real ` try! ` macro] ( #the-real-try-macro )
42
42
* [ Composing custom error types] ( #composing-custom-error-types )
43
43
* [ Advice for library writers] ( #advice-for-library-writers )
44
- * [ Case study: A program to read population data] ( #case-study: -a-program-to-read-population-data )
44
+ * [ Case study: A program to read population data] ( #case-study-a-program-to-read-population-data )
45
45
* [ Initial setup] ( #initial-setup )
46
46
* [ Argument parsing] ( #argument-parsing )
47
47
* [ Writing the logic] ( #writing-the-logic )
48
- * [ Error handling with ` Box<Error> ` ] ( #error-handling-with-box%3Cerror%3E )
48
+ * [ Error handling with ` Box<Error> ` ] ( #error-handling-with-boxerror )
49
49
* [ Reading from stdin] ( #reading-from-stdin )
50
50
* [ Error handling with a custom type] ( #error-handling-with-a-custom-type )
51
51
* [ Adding functionality] ( #adding-functionality )
@@ -87,7 +87,7 @@ thread '<main>' panicked at 'Invalid number: 11', src/bin/panic-simple.rs:5
87
87
Here's another example that is slightly less contrived. A program that accepts
88
88
an integer as an argument, doubles it and prints it.
89
89
90
- <a name =" code-unwrap-double " ></a >
90
+ <span id =" code-unwrap-double " ></span >
91
91
92
92
``` rust,should_panic
93
93
use std::env;
@@ -139,7 +139,7 @@ system is an important concept because it will cause the compiler to force the
139
139
programmer to handle that absence. Let's take a look at an example that tries
140
140
to find a character in a string:
141
141
142
- <a name =" code-option-ex-string-find " ></a >
142
+ <span id =" code-option-ex-string-find " ></span >
143
143
144
144
``` rust
145
145
// Searches `haystack` for the Unicode character `needle`. If one is found, the
@@ -186,7 +186,7 @@ But wait, what about `unwrap` used in [`unwrap-double`](#code-unwrap-double)?
186
186
There was no case analysis there! Instead, the case analysis was put inside the
187
187
` unwrap ` method for you. You could define it yourself if you want:
188
188
189
- <a name =" code-option-def-unwrap " ></a >
189
+ <span id =" code-option-def-unwrap " ></span >
190
190
191
191
``` rust
192
192
enum Option <T > {
@@ -253,7 +253,7 @@ option is `None`, in which case, just return `None`.
253
253
Rust has parametric polymorphism, so it is very easy to define a combinator
254
254
that abstracts this pattern:
255
255
256
- <a name =" code-option-map " ></a >
256
+ <span id =" code-option-map " ></span >
257
257
258
258
``` rust
259
259
fn map <F , T , A >(option : Option <T >, f : F ) -> Option <A > where F : FnOnce (T ) -> A {
@@ -394,7 +394,7 @@ remove choices because they will panic if `Option<T>` is `None`.
394
394
The ` Result ` type is also
395
395
[ defined in the standard library] [ 6 ] :
396
396
397
- <a name =" code-result-def-1 " ></a >
397
+ <span id =" code-result-def " ></span >
398
398
399
399
``` rust
400
400
enum Result <T , E > {
@@ -562,7 +562,7 @@ combinators that affect only the error type, such as
562
562
### The ` Result ` type alias idiom
563
563
564
564
In the standard library, you may frequently see types like
565
- ` Result<i32> ` . But wait, [ we defined ` Result ` ] ( #code-result-def-1 ) to
565
+ ` Result<i32> ` . But wait, [ we defined ` Result ` ] ( #code-result-def ) to
566
566
have two type parameters. How can we get away with only specifying
567
567
one? The key is to define a ` Result ` type alias that * fixes* one of
568
568
the type parameters to a particular type. Usually the fixed type is
@@ -672,7 +672,7 @@ with both an `Option` and a `Result`, the solution is *usually* to convert the
672
672
(from ` env::args() ` ) means the user didn't invoke the program correctly. We
673
673
could just use a ` String ` to describe the error. Let's try:
674
674
675
- <a name =" code-error-double-string " ></a >
675
+ <span id =" code-error-double-string " ></span >
676
676
677
677
``` rust
678
678
use std :: env;
@@ -906,7 +906,7 @@ seen above.
906
906
907
907
Here is a simplified definition of a ` try! ` macro:
908
908
909
- <a nama name =" code-try-def-simple " ></a >
909
+ <span id =" code-try-def-simple " ></span >
910
910
911
911
``` rust
912
912
macro_rules! try {
@@ -1168,7 +1168,7 @@ The `std::convert::From` trait is
1168
1168
[ defined in the standard
1169
1169
library] ( ../std/convert/trait.From.html ) :
1170
1170
1171
- <a name =" code-from-def " ></a >
1171
+ <span id =" code-from-def " ></span >
1172
1172
1173
1173
``` rust
1174
1174
trait From <T > {
@@ -1250,7 +1250,7 @@ macro_rules! try {
1250
1250
This is not its real definition. Its real definition is
1251
1251
[ in the standard library] ( ../std/macro.try!.html ) :
1252
1252
1253
- <a name =" code-try-def " ></a >
1253
+ <span id =" code-try-def " ></span >
1254
1254
1255
1255
``` rust
1256
1256
macro_rules! try {
@@ -1515,7 +1515,7 @@ and [`rustc-serialize`](https://crates.io/crates/rustc-serialize) crates.
1515
1515
1516
1516
We're not going to spend a lot of time on setting up a project with
1517
1517
Cargo because it is already covered well in [ the Cargo
1518
- chapter] ( ../book/hello-cargo ) and [ Cargo's documentation] [ 14 ] .
1518
+ chapter] ( ../book/hello-cargo.html ) and [ Cargo's documentation] [ 14 ] .
1519
1519
1520
1520
To get started from scratch, run ` cargo new --bin city-pop ` and make sure your
1521
1521
` Cargo.toml ` looks something like this:
@@ -1573,7 +1573,7 @@ fn main() {
1573
1573
1574
1574
let mut opts = Options::new();
1575
1575
opts.optflag("h", "help", "Show this usage message.");
1576
-
1576
+
1577
1577
let matches = match opts.parse(&args[1..]) {
1578
1578
Ok(m) => { m }
1579
1579
Err(e) => { panic!(e.to_string()) }
@@ -1584,7 +1584,7 @@ fn main() {
1584
1584
}
1585
1585
let data_path = args[1].clone();
1586
1586
let city = args[2].clone();
1587
-
1587
+
1588
1588
// Do stuff with information
1589
1589
}
1590
1590
```
@@ -1647,27 +1647,27 @@ fn main() {
1647
1647
1648
1648
let mut opts = Options::new();
1649
1649
opts.optflag("h", "help", "Show this usage message.");
1650
-
1650
+
1651
1651
let matches = match opts.parse(&args[1..]) {
1652
1652
Ok(m) => { m }
1653
1653
Err(e) => { panic!(e.to_string()) }
1654
1654
};
1655
-
1655
+
1656
1656
if matches.opt_present("h") {
1657
1657
print_usage(&program, opts);
1658
1658
return;
1659
1659
}
1660
-
1660
+
1661
1661
let data_file = args[1].clone();
1662
1662
let data_path = Path::new(&data_file);
1663
1663
let city = args[2].clone();
1664
-
1664
+
1665
1665
let file = fs::File::open(data_path).unwrap();
1666
1666
let mut rdr = csv::Reader::from_reader(file);
1667
-
1667
+
1668
1668
for row in rdr.decode::<Row>() {
1669
1669
let row = row.unwrap();
1670
-
1670
+
1671
1671
if row.city == city {
1672
1672
println!("{}, {}: {:?}",
1673
1673
row.city, row.country,
@@ -1773,7 +1773,7 @@ fn main() {
1773
1773
print_usage(&program, opts);
1774
1774
return;
1775
1775
}
1776
-
1776
+
1777
1777
let data_file = args[1].clone();
1778
1778
let data_path = Path::new(&data_file);
1779
1779
let city = args[2].clone();
@@ -1882,7 +1882,7 @@ opts.optflag("h", "help", "Show this usage message.");
1882
1882
...
1883
1883
let file = matches.opt_str("f");
1884
1884
let data_file = file.as_ref().map(Path::new);
1885
-
1885
+
1886
1886
let city = if !matches.free.is_empty() {
1887
1887
matches.free[0].clone()
1888
1888
} else {
0 commit comments