Skip to content

Commit 543bb03

Browse files
committed
Auto merge of #30690 - LawrenceWoodman:patch-2, r=steveklabnik
`fs::File` was being referenced without either calling via `std::fs::File` or by using `File` after having used `std::fs::File`. Also `Path` was being referenced without first having used `std::path::Path`.
2 parents 191ff2d + 0c3d6b4 commit 543bb03

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/doc/book/error-handling.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1613,6 +1613,9 @@ CSV data given to us and print out a field in matching rows. Let's do it. (Make
16131613
sure to add `extern crate csv;` to the top of your file.)
16141614

16151615
```rust,ignore
1616+
use std::fs::File;
1617+
use std::path::Path;
1618+
16161619
// This struct represents the data in each row of the CSV file.
16171620
// Type based decoding absolves us of a lot of the nitty gritty error
16181621
// handling, like parsing strings as integers or floats.
@@ -1656,7 +1659,7 @@ fn main() {
16561659
let data_path = Path::new(&data_file);
16571660
let city = args[2].clone();
16581661
1659-
let file = fs::File::open(data_path).unwrap();
1662+
let file = File::open(data_path).unwrap();
16601663
let mut rdr = csv::Reader::from_reader(file);
16611664
16621665
for row in rdr.decode::<Row>() {
@@ -1674,7 +1677,7 @@ fn main() {
16741677
Let's outline the errors. We can start with the obvious: the three places that
16751678
`unwrap` is called:
16761679

1677-
1. [`fs::File::open`](../std/fs/struct.File.html#method.open)
1680+
1. [`File::open`](../std/fs/struct.File.html#method.open)
16781681
can return an
16791682
[`io::Error`](../std/io/struct.Error.html).
16801683
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) {
17341737
17351738
fn search<P: AsRef<Path>>(file_path: P, city: &str) -> Vec<PopulationCount> {
17361739
let mut found = vec![];
1737-
let file = fs::File::open(file_path).unwrap();
1740+
let file = File::open(file_path).unwrap();
17381741
let mut rdr = csv::Reader::from_reader(file);
17391742
for row in rdr.decode::<Row>() {
17401743
let row = row.unwrap();
@@ -1796,7 +1799,7 @@ fn search<P: AsRef<Path>>
17961799
(file_path: P, city: &str)
17971800
-> Result<Vec<PopulationCount>, Box<Error+Send+Sync>> {
17981801
let mut found = vec![];
1799-
let file = try!(fs::File::open(file_path));
1802+
let file = try!(File::open(file_path));
18001803
let mut rdr = csv::Reader::from_reader(file);
18011804
for row in rdr.decode::<Row>() {
18021805
let row = try!(row);
@@ -1930,7 +1933,7 @@ fn search<P: AsRef<Path>>
19301933
let mut found = vec![];
19311934
let input: Box<io::Read> = match *file_path {
19321935
None => Box::new(io::stdin()),
1933-
Some(ref file_path) => Box::new(try!(fs::File::open(file_path))),
1936+
Some(ref file_path) => Box::new(try!(File::open(file_path))),
19341937
};
19351938
let mut rdr = csv::Reader::from_reader(input);
19361939
// The rest remains unchanged!
@@ -2017,7 +2020,7 @@ fn search<P: AsRef<Path>>
20172020
let mut found = vec![];
20182021
let input: Box<io::Read> = match *file_path {
20192022
None => Box::new(io::stdin()),
2020-
Some(ref file_path) => Box::new(try!(fs::File::open(file_path))),
2023+
Some(ref file_path) => Box::new(try!(File::open(file_path))),
20212024
};
20222025
let mut rdr = csv::Reader::from_reader(input);
20232026
for row in rdr.decode::<Row>() {

0 commit comments

Comments
 (0)