Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Rust_lekstuga
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Nilsson
Rust_lekstuga
Commits
bc0527e3
Commit
bc0527e3
authored
9 years ago
by
Administrator
Browse files
Options
Downloads
Patches
Plain Diff
Better error handling, database file as input option
parent
8a5c2117
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
city-pop/src/main.rs
+6
-3
6 additions, 3 deletions
city-pop/src/main.rs
with
6 additions
and
3 deletions
city-pop/src/main.rs
+
6
−
3
View file @
bc0527e3
...
@@ -4,7 +4,7 @@ extern crate csv;
...
@@ -4,7 +4,7 @@ extern crate csv;
use
getopts
::
Options
;
use
getopts
::
Options
;
use
std
::{
env
,
fs
};
use
std
::{
env
,
fs
,
io
};
use
std
::
error
::
Error
;
use
std
::
error
::
Error
;
use
std
::
path
::
Path
;
use
std
::
path
::
Path
;
...
@@ -49,8 +49,11 @@ fn print_usage(program: &str, opts: Options) {
...
@@ -49,8 +49,11 @@ fn print_usage(program: &str, opts: Options) {
fn
search
<
P
:
AsRef
<
Path
>>
(
file_path
:
&
Option
<
P
>
,
city
:
&
str
)
fn
search
<
P
:
AsRef
<
Path
>>
(
file_path
:
&
Option
<
P
>
,
city
:
&
str
)
->
Result
<
Vec
<
PopulationCount
>
,
Box
<
Error
+
Send
+
Sync
>>
{
->
Result
<
Vec
<
PopulationCount
>
,
Box
<
Error
+
Send
+
Sync
>>
{
let
mut
found
=
vec!
[];
let
mut
found
=
vec!
[];
let
file
=
try
!
(
fs
::
File
::
open
(
file_path
));
let
input
:
Box
<
io
::
Read
>
=
match
*
file_path
{
let
mut
rdr
=
csv
::
Reader
::
from_reader
(
file
);
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
>
()
{
for
row
in
rdr
.decode
::
<
Row
>
()
{
let
row
=
row
.unwrap
();
let
row
=
row
.unwrap
();
match
row
.population
{
match
row
.population
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment