From 0c3d6b46acce5d5fce9565d5e5b83f0b4e4fefbc Mon Sep 17 00:00:00 2001 From: Lawrence Woodman Date: Mon, 4 Jan 2016 07:21:48 +0000 Subject: [PATCH] Add missing use statements fs::File was being referenced without either calling via std::fs::File or by using File after having used fs::File. Also Path was being referenced without first having used std::path::Path. --- src/doc/book/error-handling.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/doc/book/error-handling.md b/src/doc/book/error-handling.md index 3479230f77468..be60ea8f81fc3 100644 --- a/src/doc/book/error-handling.md +++ b/src/doc/book/error-handling.md @@ -1613,6 +1613,9 @@ CSV data given to us and print out a field in matching rows. Let's do it. (Make sure to add `extern crate csv;` to the top of your file.) ```rust,ignore +use std::fs::File; +use std::path::Path; + // This struct represents the data in each row of the CSV file. // Type based decoding absolves us of a lot of the nitty gritty error // handling, like parsing strings as integers or floats. @@ -1656,7 +1659,7 @@ fn main() { let data_path = Path::new(&data_file); let city = args[2].clone(); - let file = fs::File::open(data_path).unwrap(); + let file = File::open(data_path).unwrap(); let mut rdr = csv::Reader::from_reader(file); for row in rdr.decode::() { @@ -1674,7 +1677,7 @@ fn main() { Let's outline the errors. We can start with the obvious: the three places that `unwrap` is called: -1. [`fs::File::open`](../std/fs/struct.File.html#method.open) +1. [`File::open`](../std/fs/struct.File.html#method.open) can return an [`io::Error`](../std/io/struct.Error.html). 2. [`csv::Reader::decode`](http://burntsushi.net/rustdoc/csv/struct.Reader.html#method.decode) @@ -1734,7 +1737,7 @@ fn print_usage(program: &str, opts: Options) { fn search>(file_path: P, city: &str) -> Vec { let mut found = vec![]; - let file = fs::File::open(file_path).unwrap(); + let file = File::open(file_path).unwrap(); let mut rdr = csv::Reader::from_reader(file); for row in rdr.decode::() { let row = row.unwrap(); @@ -1796,7 +1799,7 @@ fn search> (file_path: P, city: &str) -> Result, Box> { let mut found = vec![]; - let file = try!(fs::File::open(file_path)); + let file = try!(File::open(file_path)); let mut rdr = csv::Reader::from_reader(file); for row in rdr.decode::() { let row = try!(row); @@ -1930,7 +1933,7 @@ fn search> let mut found = vec![]; let input: Box = match *file_path { None => Box::new(io::stdin()), - Some(ref file_path) => Box::new(try!(fs::File::open(file_path))), + Some(ref file_path) => Box::new(try!(File::open(file_path))), }; let mut rdr = csv::Reader::from_reader(input); // The rest remains unchanged! @@ -2017,7 +2020,7 @@ fn search> let mut found = vec![]; let input: Box = match *file_path { None => Box::new(io::stdin()), - Some(ref file_path) => Box::new(try!(fs::File::open(file_path))), + Some(ref file_path) => Box::new(try!(File::open(file_path))), }; let mut rdr = csv::Reader::from_reader(input); for row in rdr.decode::() {