about summary refs log tree commit diff
diff options
context:
space:
mode:
authorjrburke <jrburke@gmail.com>2015-11-07 21:36:57 -0800
committerjrburke <jrburke@gmail.com>2015-11-08 09:53:21 -0800
commit0dd2c1c07dd2483618790262a2a661fee34c992f (patch)
tree01ab9a432fe8e6ab63594dfa458d9e595b21f955
parent01fc81f249cf8d81bbb5f1d6675bfb14fe20afdd (diff)
downloadrust-0dd2c1c07dd2483618790262a2a661fee34c992f.tar.gz
rust-0dd2c1c07dd2483618790262a2a661fee34c992f.zip
doc: error-handling.md: main case analysis for search
-rw-r--r--src/doc/trpl/error-handling.md16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/doc/trpl/error-handling.md b/src/doc/trpl/error-handling.md
index 68671cef707..52a4e7324ee 100644
--- a/src/doc/trpl/error-handling.md
+++ b/src/doc/trpl/error-handling.md
@@ -1838,6 +1838,22 @@ impl<'a, 'b> From<&'b str> for Box<Error + Send + Sync + 'a>
 impl From<String> for Box<Error + Send + Sync>
 ```
 
+Since `search` now returns a `Result<T, E>`, `main` should use case analysis
+when calling `search`:
+
+```rust,ignore
+...
+match search(&data_file, &city) {
+    Ok(pops) => {
+        for pop in pops {
+            println!("{}, {}: {:?}", pop.city, pop.country, pop.count);
+        }
+    }
+    Err(err) => println!("{}", err)
+}
+...
+```
+
 Now that we've seen how to do proper error handling with `Box<Error>`, let's
 try a different approach with our own custom error type. But first, let's take
 a quick break from error handling and add support for reading from `stdin`.