Skip to content
Snippets Groups Projects
Commit bc0527e3 authored by Administrator's avatar Administrator
Browse files

Better error handling, database file as input option

parent 8a5c2117
Branches
No related tags found
No related merge requests found
......@@ -4,7 +4,7 @@ extern crate csv;
use getopts::Options;
use std::{env,fs};
use std::{env,fs,io};
use std::error::Error;
use std::path::Path;
......@@ -49,8 +49,11 @@ fn print_usage(program: &str, opts: Options) {
fn search<P: AsRef<Path>> (file_path: &Option<P>, city: &str)
-> Result<Vec<PopulationCount>, Box<Error+Send+Sync>> {
let mut found = vec![];
let file = try!(fs::File::open(file_path));
let mut rdr = csv::Reader::from_reader(file);
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))),
};
let mut rdr = csv::Reader::from_reader(input);
for row in rdr.decode::<Row>() {
let row = row.unwrap();
match row.population {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment