@@ -21,35 +21,35 @@ sum types and combinators, and try to motivate the way Rust does error handling
21
21
incrementally. As such, programmers with experience in other expressive type
22
22
systems may want to jump around.
23
23
24
- * [ The Basics] ( #The%20Basics )
25
- * [ Unwrapping explained] ( #Unwrapping%20explained )
26
- * [ The ` Option ` type] ( #The%20Option%20type )
27
- * [ Composing ` Option<T> ` values] ( #Composing%20Option%3CT%3E%20values )
28
- * [ The ` Result ` type] ( #The%20Result%20type )
29
- * [ Parsing integers] ( #Parsing%20integers )
30
- * [ The ` Result ` type alias idiom] ( #The%20Result%20type%20alias%20idiom )
31
- * [ A brief interlude: unwrapping isn't evil] ( #A%20brief%20interlude:%20unwrapping%20isnt%20evil )
32
- * [ Working with multiple error types] ( #Working%20with%20multiple%20error%20types )
33
- * [ Composing ` Option ` and ` Result ` ] ( #Composing%20Option%20and%20Result )
34
- * [ The limits of combinators] ( #The%20limits%20of%20combinators )
35
- * [ Early returns] ( #Early%20returns )
36
- * [ The ` try! ` macro] ( #The%20try%20macro )
37
- * [ Defining your own error type] ( #Defining%20your%20own%20error%20type )
38
- * [ Standard library traits used for error handling] ( #Standard%20library%20traits%20used%20for%20error%20handling )
39
- * [ The ` Error ` trait] ( #The%20Error%20trait )
40
- * [ The ` From ` trait] ( #The%20From%20trait )
41
- * [ The real ` try! ` macro] ( #The%20real%20try%20macro )
42
- * [ Composing custom error types] ( #Composing%20custom%20error%20types )
43
- * [ Advice for library writers] ( #Advice%20for%20library%20writers )
44
- * [ Case study: A program to read population data] ( #Case%20study:%20A%20program%20to%20read%20population%20data )
45
- * [ Initial setup] ( #Initial%20setup )
46
- * [ Argument parsing] ( #Argument%20parsing )
47
- * [ Writing the logic] ( #Writing%20the%20logic )
48
- * [ Error handling with ` Box<Error> ` ] ( #Error%20handling%20with%20Box%3CError%3E )
49
- * [ Reading from stdin] ( #Reading%20from%20stdin )
50
- * [ Error handling with a custom type] ( #Error%20handling%20with%20a%20custom%20type )
51
- * [ Adding functionality] ( #Adding%20functionality )
52
- * [ The short story] ( #The%20short%20story )
24
+ * [ The Basics] ( #the-basics )
25
+ * [ Unwrapping explained] ( #unwrapping-explained )
26
+ * [ The ` Option ` type] ( #the-option-type )
27
+ * [ Composing ` Option<T> ` values] ( #composing-optiont-values )
28
+ * [ The ` Result ` type] ( #the-result-type )
29
+ * [ Parsing integers] ( #parsing-integers )
30
+ * [ The ` Result ` type alias idiom] ( #the-result-type-alias-idiom )
31
+ * [ A brief interlude: unwrapping isn't evil] ( #a-brief-interlude-unwrapping-isnt-evil )
32
+ * [ Working with multiple error types] ( #working-with-multiple-error-types )
33
+ * [ Composing ` Option ` and ` Result ` ] ( #composing-option-and-result )
34
+ * [ The limits of combinators] ( #the-limits-of-combinators )
35
+ * [ Early returns] ( #early-returns )
36
+ * [ The ` try! ` macro] ( #the-try-macro )
37
+ * [ Defining your own error type] ( #defining-your-own-error-type )
38
+ * [ Standard library traits used for error handling] ( #standard-library-traits-used-for-error-handling )
39
+ * [ The ` Error ` trait] ( #the-error-trait )
40
+ * [ The ` From ` trait] ( #the-from-trait )
41
+ * [ The real ` try! ` macro] ( #the-real-try-macro )
42
+ * [ Composing custom error types] ( #composing-custom-error-types )
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 )
45
+ * [ Initial setup] ( #initial-setup )
46
+ * [ Argument parsing] ( #argument-parsing )
47
+ * [ Writing the logic] ( #writing-the-logic )
48
+ * [ Error handling with ` Box<Error> ` ] ( #error-handling-with-boxerror )
49
+ * [ Reading from stdin] ( #reading-from-stdin )
50
+ * [ Error handling with a custom type] ( #error-handling-with-a-custom-type )
51
+ * [ Adding functionality] ( #adding-functionality )
52
+ * [ The short story] ( #the-short-story )
53
53
54
54
# The Basics
55
55
@@ -796,7 +796,7 @@ because of the return types of
796
796
[ ` std::fs::File::open ` ] ( ../std/fs/struct.File.html#method.open ) and
797
797
[ ` std::io::Read::read_to_string ` ] ( ../std/io/trait.Read.html#method.read_to_string ) .
798
798
(Note that they both use the [ ` Result ` type alias
799
- idiom] ( #The%20Result%20type%20alias%20idiom ) described previously. If you
799
+ idiom] ( #the-result-type-alias-idiom ) described previously. If you
800
800
click on the ` Result ` type, you'll [ see the type
801
801
alias] ( ../std/io/type.Result.html ) , and consequently, the underlying
802
802
` io::Error ` type.) The third problem is described by the
@@ -1120,7 +1120,7 @@ returns an `&Error`, which is itself a trait object. We'll revisit the
1120
1120
1121
1121
For now, it suffices to show an example implementing the ` Error ` trait. Let's
1122
1122
use the error type we defined in the
1123
- [ previous section] ( #Defining%20your%20own%20error%20type ) :
1123
+ [ previous section] ( #defining-your-own-error-type ) :
1124
1124
1125
1125
``` rust
1126
1126
use std :: io;
@@ -1493,19 +1493,19 @@ representation. But certainly, this will vary depending on use cases.
1493
1493
At a minimum, you should probably implement the
1494
1494
[ ` Error ` ] ( ../std/error/trait.Error.html )
1495
1495
trait. This will give users of your library some minimum flexibility for
1496
- [ composing errors] ( #The%20real%20try%20macro ) . Implementing the ` Error ` trait also
1496
+ [ composing errors] ( #the-real-try-macro ) . Implementing the ` Error ` trait also
1497
1497
means that users are guaranteed the ability to obtain a string representation
1498
1498
of an error (because it requires impls for both ` fmt::Debug ` and
1499
1499
` fmt::Display ` ).
1500
1500
1501
1501
Beyond that, it can also be useful to provide implementations of ` From ` on your
1502
1502
error types. This allows you (the library author) and your users to
1503
- [ compose more detailed errors] ( #Composing%20custom%20error%20types ) . For example,
1503
+ [ compose more detailed errors] ( #composing-custom-error-types ) . For example,
1504
1504
[ ` csv::Error ` ] ( http://burntsushi.net/rustdoc/csv/enum.Error.html )
1505
1505
provides ` From ` impls for both ` io::Error ` and ` byteorder::Error ` .
1506
1506
1507
1507
Finally, depending on your tastes, you may also want to define a
1508
- [ ` Result ` type alias] ( #The%20Result%20type%20alias%20idiom ) , particularly if your
1508
+ [ ` Result ` type alias] ( #the-result-type-alias-idiom ) , particularly if your
1509
1509
library defines a single error type. This is used in the standard library
1510
1510
for [ ` io::Result ` ] ( ../std/io/type.Result.html )
1511
1511
and [ ` fmt::Result ` ] ( ../std/fmt/type.Result.html ) .
@@ -1538,7 +1538,7 @@ and [`rustc-serialize`](https://crates.io/crates/rustc-serialize) crates.
1538
1538
1539
1539
We're not going to spend a lot of time on setting up a project with
1540
1540
Cargo because it is already covered well in [ the Cargo
1541
- section] ( getting-started.html#Hello%20Cargo ) and [ Cargo's documentation] [ 14 ] .
1541
+ section] ( getting-started.html#hello-cargo ) and [ Cargo's documentation] [ 14 ] .
1542
1542
1543
1543
To get started from scratch, run ` cargo new --bin city-pop ` and make sure your
1544
1544
` Cargo.toml ` looks something like this:
@@ -1729,7 +1729,7 @@ error types and you don't need any `From` implementations. The downside is that
1729
1729
since ` Box<Error> ` is a trait object, it * erases the type* , which means the
1730
1730
compiler can no longer reason about its underlying type.
1731
1731
1732
- [ Previously] ( #The%20limits%20of%20combinators ) we started refactoring our code by
1732
+ [ Previously] ( #the-limits-of-combinators ) we started refactoring our code by
1733
1733
changing the type of our function from ` T ` to ` Result<T, OurErrorType> ` . In
1734
1734
this case, ` OurErrorType ` is only ` Box<Error> ` . But what's ` T ` ? And can we add
1735
1735
a return type to ` main ` ?
0 commit comments