diff options
| author | Lawrence Woodman <lwoodman@vlifesystems.com> | 2016-01-04 07:21:48 +0000 |
|---|---|---|
| committer | Lawrence Woodman <lwoodman@vlifesystems.com> | 2016-01-04 07:21:48 +0000 |
| commit | 0c3d6b46acce5d5fce9565d5e5b83f0b4e4fefbc (patch) | |
| tree | 397e11c6c7758ba7e30e1a1ac12d1b152cfd2f00 /src | |
| parent | 99e59dec5a8781817b4a1858535b1ffe11b8f735 (diff) | |
| download | rust-0c3d6b46acce5d5fce9565d5e5b83f0b4e4fefbc.tar.gz rust-0c3d6b46acce5d5fce9565d5e5b83f0b4e4fefbc.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/doc/book/error-handling.md | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/doc/book/error-handling.md b/src/doc/book/error-handling.md index 3479230f774..be60ea8f81f 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::<Row>() { @@ -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<P: AsRef<Path>>(file_path: P, city: &str) -> Vec<PopulationCount> { 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::<Row>() { let row = row.unwrap(); @@ -1796,7 +1799,7 @@ fn search<P: AsRef<Path>> (file_path: P, city: &str) -> Result<Vec<PopulationCount>, Box<Error+Send+Sync>> { 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::<Row>() { let row = try!(row); @@ -1930,7 +1933,7 @@ fn search<P: AsRef<Path>> let mut found = vec![]; let input: Box<io::Read> = 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<P: AsRef<Path>> let mut found = vec![]; let input: Box<io::Read> = 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::<Row>() { |
