File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
episode/9/rust/pascal/src Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,13 @@ use rayon::prelude::*;
55use structopt:: StructOpt ;
66use std:: collections:: HashMap ;
77use std:: fs;
8+ use std:: path:: { PathBuf , Path } ;
89use std:: sync:: Mutex ;
910
1011#[ derive( StructOpt ) ]
1112struct 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 ( ) {
You can’t perform that action at this time.
0 commit comments