@@ -28,7 +28,7 @@ systems may want to jump around.
2828 * [ The ` Result ` type] ( #the-result-type )
2929 * [ Parsing integers] ( #parsing-integers )
3030 * [ The ` Result ` type alias idiom] ( #the-result-type-alias-idiom )
31- * [ A brief interlude: unwrapping isn't evil] ( #a-brief-interlude-unwrapping-isnt -evil )
31+ * [ A brief interlude: unwrapping isn't evil] ( #a-brief-interlude: -unwrapping-isn't -evil )
3232* [ Working with multiple error types] ( #working-with-multiple-error-types )
3333 * [ Composing ` Option ` and ` Result ` ] ( #composing-option-and-result )
3434 * [ The limits of combinators] ( #the-limits-of-combinators )
@@ -41,11 +41,11 @@ systems may want to jump around.
4141 * [ The real ` try! ` macro] ( #the-real-try!-macro )
4242 * [ Composing custom error types] ( #composing-custom-error-types )
4343 * [ 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 )
4545 * [ Initial setup] ( #initial-setup )
4646 * [ Argument parsing] ( #argument-parsing )
4747 * [ Writing the logic] ( #writing-the-logic )
48- * [ Error handling with ` Box<Error> ` ] ( #error-handling-with-box<error> )
48+ * [ Error handling with ` Box<Error> ` ] ( #error-handling-with-box%3Cerror%3E )
4949 * [ Reading from stdin] ( #reading-from-stdin )
5050 * [ Error handling with a custom type] ( #error-handling-with-a-custom-type )
5151 * [ Adding functionality] ( #adding-functionality )
@@ -87,9 +87,9 @@ thread '<main>' panicked at 'Invalid number: 11', src/bin/panic-simple.rs:5
8787Here's another example that is slightly less contrived. A program that accepts
8888an integer as an argument, doubles it and prints it.
8989
90- <div id =" code-unwrap-double " >
91- ``` rust,should_panic
90+ <a name =" code-unwrap-double " ></a >
9291
92+ ``` rust,should_panic
9393use std::env;
9494
9595fn main() {
@@ -99,7 +99,6 @@ fn main() {
9999 println!("{}", 2 * n);
100100}
101101```
102- </div >
103102
104103If you give this program zero arguments (error 1) or if the first argument
105104isn't an integer (error 2), the program will panic just like in the first
@@ -140,7 +139,8 @@ system is an important concept because it will cause the compiler to force the
140139programmer to handle that absence. Let's take a look at an example that tries
141140to find a character in a string:
142141
143- <div id =" code-option-ex-string-find " >
142+ <a name =" code-option-ex-string-find " ></a >
143+
144144``` rust
145145// Searches `haystack` for the Unicode character `needle`. If one is found, the
146146// byte offset of the character is returned. Otherwise, `None` is returned.
@@ -153,7 +153,6 @@ fn find(haystack: &str, needle: char) -> Option<usize> {
153153 None
154154}
155155```
156- </div >
157156
158157Notice that when this function finds a matching character, it doen't just
159158return the ` offset ` . Instead, it returns ` Some(offset) ` . ` Some ` is a variant or
@@ -187,6 +186,8 @@ But wait, what about `unwrap` used in [`unwrap-double`](#code-unwrap-double)?
187186There was no case analysis there! Instead, the case analysis was put inside the
188187` unwrap ` method for you. You could define it yourself if you want:
189188
189+ <a name =" code-option-def-unwrap " ></a >
190+
190191``` rust
191192enum Option <T > {
192193 None ,
@@ -210,7 +211,7 @@ that makes `unwrap` ergonomic to use. Unfortunately, that `panic!` means that
210211
211212### Composing ` Option<T> ` values
212213
213- In [ ` option-ex-string-find ` ] ( #code-option-ex-string-find-2 )
214+ In [ ` option-ex-string-find ` ] ( #code-option-ex-string-find )
214215we saw how to use ` find ` to discover the extension in a file name. Of course,
215216not all file names have a ` . ` in them, so it's possible that the file name has
216217no extension. This * possibility of absence* is encoded into the types using
@@ -252,6 +253,8 @@ option is `None`, in which case, just return `None`.
252253Rust has parametric polymorphism, so it is very easy to define a combinator
253254that abstracts this pattern:
254255
256+ <a name =" code-option-map " ></a >
257+
255258``` rust
256259fn map <F , T , A >(option : Option <T >, f : F ) -> Option <A > where F : FnOnce (T ) -> A {
257260 match option {
@@ -391,6 +394,8 @@ remove choices because they will panic if `Option<T>` is `None`.
391394The ` Result ` type is also
392395[ defined in the standard library] [ 6 ] :
393396
397+ <a name =" code-result-def-1 " ></a >
398+
394399``` rust
395400enum Result <T , E > {
396401 Ok (T ),
@@ -667,6 +672,8 @@ with both an `Option` and a `Result`, the solution is *usually* to convert the
667672(from ` env::args() ` ) means the user didn't invoke the program correctly. We
668673could just use a ` String ` to describe the error. Let's try:
669674
675+ <a name =" code-error-double-string " ></a >
676+
670677``` rust
671678use std :: env;
672679
@@ -899,6 +906,8 @@ seen above.
899906
900907Here is a simplified definition of a ` try! ` macro:
901908
909+ <a nama name =" code-try-def-simple " ></a >
910+
902911``` rust
903912macro_rules! try {
904913 ($ e : expr ) => (match $ e {
@@ -1159,6 +1168,8 @@ The `std::convert::From` trait is
11591168[ defined in the standard
11601169library] ( ../std/convert/trait.From.html ) :
11611170
1171+ <a name =" code-from-def " ></a >
1172+
11621173``` rust
11631174trait From <T > {
11641175 fn from (T ) -> Self ;
@@ -1236,9 +1247,11 @@ macro_rules! try {
12361247}
12371248```
12381249
1239- This is not it's real definition. It's real definition is
1250+ This is not its real definition. Its real definition is
12401251[ in the standard library] ( ../std/macro.try!.html ) :
12411252
1253+ <a name =" code-try-def " ></a >
1254+
12421255``` rust
12431256macro_rules! try {
12441257 ($ e : expr ) => (match $ e {
@@ -1457,7 +1470,7 @@ representation. But certainly, this will vary depending on use cases.
14571470At a minimum, you should probably implement the
14581471[ ` Error ` ] ( ../std/error/trait.Error.html )
14591472trait. This will give users of your library some minimum flexibility for
1460- [ composing errors] ( #the-real-try-macro ) . Implementing the ` Error ` trait also
1473+ [ composing errors] ( #the-real-try! -macro ) . Implementing the ` Error ` trait also
14611474means that users are guaranteed the ability to obtain a string representation
14621475of an error (because it requires impls for both ` fmt::Debug ` and
14631476` fmt::Display ` ).
0 commit comments