Skip to content

Commit ea4896d

Browse files
committed
Actually, file names are PathBufs not Strings
Super tiny thing but why not support people's non UTF8 file names?
1 parent f8602e6 commit ea4896d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

episode/9/rust/pascal/src/main.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ use rayon::prelude::*;
55
use structopt::StructOpt;
66
use std::collections::HashMap;
77
use std::fs;
8+
use std::path::{PathBuf, Path};
89
use std::sync::Mutex;
910

1011
#[derive(StructOpt)]
1112
struct Cli {
12-
files: Vec<String>,
13+
#[structopt(name = "FILE", parse(from_os_str))]
14+
files: Vec<PathBuf>,
1315
}
1416

1517
#[derive(Debug)]
@@ -25,7 +27,7 @@ fn main() -> Result<(), Box<Error>> {
2527

2628
args.files
2729
.par_iter()
28-
.for_each(|arg| tally_words(arg.to_string(), &w).unwrap());
30+
.for_each(|filename| tally_words(filename, &w).unwrap());
2931

3032
let words = w.lock().map_err(|_| Error::Lock)?;
3133
for (word, count) in words.iter() {
@@ -37,7 +39,7 @@ fn main() -> Result<(), Box<Error>> {
3739
Ok(())
3840
}
3941

40-
fn tally_words(filename: String, w: &Words) -> Result<(), Box<Error>> {
42+
fn tally_words(filename: &Path, w: &Words) -> Result<(), Box<Error>> {
4143
let contents = fs::read_to_string(filename).expect("Unable to read file");
4244

4345
for s in contents.split_whitespace() {

0 commit comments

Comments
 (0)