@@ -291,27 +291,15 @@ fn prepare_reader(
291291 let mut reader: Box < dyn BufRead > = if path == "-" {
292292 Box :: new ( BufReader :: new ( io:: stdin ( ) ) )
293293 } else {
294- match fs:: File :: open ( path) {
295- Ok ( file) => Box :: new ( BufReader :: new ( file) ) ,
296- Err ( e) => {
297- return Err ( format_failure_to_read_input_file (
298- & params. executable ,
299- path,
300- & e,
301- ) ) ;
302- }
303- }
294+ let file = fs:: File :: open ( path)
295+ . map_err ( |e| format_failure_to_read_input_file ( & params. executable , path, & e) ) ?;
296+ Box :: new ( BufReader :: new ( file) )
304297 } ;
305298
306299 if let Some ( skip) = skip {
307300 // cast as u64 must remain, because value of IgnInit data type could be changed.
308- if let Err ( e) = io:: copy ( & mut reader. by_ref ( ) . take ( * skip) , & mut io:: sink ( ) ) {
309- return Err ( format_failure_to_read_input_file (
310- & params. executable ,
311- path,
312- & e,
313- ) ) ;
314- }
301+ io:: copy ( & mut reader. by_ref ( ) . take ( * skip) , & mut io:: sink ( ) )
302+ . map_err ( |e| format_failure_to_read_input_file ( & params. executable , path, & e) ) ?;
315303 }
316304
317305 Ok ( reader)
@@ -358,27 +346,13 @@ pub fn cmp(params: &Params) -> Result<Cmp, String> {
358346 let mut compare = Cmp :: Equal ;
359347 loop {
360348 // Fill up our buffers.
361- let from_buf = match from. fill_buf ( ) {
362- Ok ( buf) => buf,
363- Err ( e) => {
364- return Err ( format_failure_to_read_input_file (
365- & params. executable ,
366- & params. from ,
367- & e,
368- ) ) ;
369- }
370- } ;
349+ let from_buf = from
350+ . fill_buf ( )
351+ . map_err ( |e| format_failure_to_read_input_file ( & params. executable , & params. from , & e) ) ?;
371352
372- let to_buf = match to. fill_buf ( ) {
373- Ok ( buf) => buf,
374- Err ( e) => {
375- return Err ( format_failure_to_read_input_file (
376- & params. executable ,
377- & params. to ,
378- & e,
379- ) ) ;
380- }
381- } ;
353+ let to_buf = to
354+ . fill_buf ( )
355+ . map_err ( |e| format_failure_to_read_input_file ( & params. executable , & params. to , & e) ) ?;
382356
383357 // Check for EOF conditions.
384358 if from_buf. is_empty ( ) && to_buf. is_empty ( ) {
0 commit comments