From ca1f0c9b644cb6811c7b98e235e36d3bf59c7d51 Mon Sep 17 00:00:00 2001 From: Lawrence Woodman Date: Tue, 5 Jan 2016 11:09:39 +0000 Subject: [PATCH 1/2] Add correct use for Error and io This also repeated the case analysis used. --- src/doc/book/error-handling.md | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/doc/book/error-handling.md b/src/doc/book/error-handling.md index be60ea8f81fc3..8c1a138ec4825 100644 --- a/src/doc/book/error-handling.md +++ b/src/doc/book/error-handling.md @@ -1795,6 +1795,10 @@ To convert this to proper error handling, we need to do the following: Let's try it: ```rust,ignore +use std::error::Error + +// The rest of the code before this is unchanged + fn search> (file_path: P, city: &str) -> Result, Box> { @@ -1903,8 +1907,13 @@ let city = if !matches.free.is_empty() { return; }; -for pop in search(&data_file, &city) { - println!("{}, {}: {:?}", pop.city, pop.country, pop.count); +match search(&data_file, &city) { + Ok(pops) => { + for pop in pops { + println!("{}, {}: {:?}", pop.city, pop.country, pop.count); + } + } + Err(err) => println!("{}", err) } ... ``` @@ -1927,6 +1936,10 @@ that it is generic on some type parameter `R` that satisfies `io::Read`. Another way is to just use trait objects: ```rust,ignore +use std::io; + +// The rest of the code before this is unchanged + fn search> (file_path: &Option

, city: &str) -> Result, Box> { From 0ca33adabf87d505d4a871c4b87cb56952f83995 Mon Sep 17 00:00:00 2001 From: Lawrence Woodman Date: Wed, 6 Jan 2016 06:27:29 +0000 Subject: [PATCH 2/2] Add missing semi-colon --- src/doc/book/error-handling.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/book/error-handling.md b/src/doc/book/error-handling.md index 8c1a138ec4825..8d392655cb3ff 100644 --- a/src/doc/book/error-handling.md +++ b/src/doc/book/error-handling.md @@ -1795,7 +1795,7 @@ To convert this to proper error handling, we need to do the following: Let's try it: ```rust,ignore -use std::error::Error +use std::error::Error; // The rest of the code before this is unchanged