@@ -432,12 +432,14 @@ fn build_options(
432432
433433 let header = matches
434434 . get_one :: < String > ( options:: HEADER )
435- . map ( |s| s. as_str ( ) )
436- . unwrap_or ( if is_merge_mode || paths[ 0 ] == FILE_STDIN {
437- ""
438- } else {
439- paths[ 0 ]
440- } )
435+ . map_or (
436+ if is_merge_mode || paths[ 0 ] == FILE_STDIN {
437+ ""
438+ } else {
439+ paths[ 0 ]
440+ } ,
441+ |s| s. as_str ( ) ,
442+ )
441443 . to_string ( ) ;
442444
443445 let default_first_number = NumberingMode :: default ( ) . first_number ;
@@ -604,8 +606,7 @@ fn build_options(
604606 Some ( x) => Some ( x) ,
605607 None => matches. get_one :: < String > ( options:: COLUMN_CHAR_SEPARATOR ) ,
606608 }
607- . map ( ToString :: to_string)
608- . unwrap_or_else ( || DEFAULT_COLUMN_SEPARATOR . to_string ( ) ) ;
609+ . map_or_else ( || DEFAULT_COLUMN_SEPARATOR . to_string ( ) , ToString :: to_string) ;
609610
610611 let default_column_width = if matches. contains_id ( options:: COLUMN_WIDTH )
611612 && matches. contains_id ( options:: COLUMN_CHAR_SEPARATOR )
@@ -659,26 +660,25 @@ fn build_options(
659660 let offset_spaces = " " . repeat ( parse_usize ( matches, options:: INDENT ) . unwrap_or ( Ok ( 0 ) ) ?) ;
660661 let join_lines = matches. get_flag ( options:: JOIN_LINES ) ;
661662
662- let col_sep_for_printing = column_mode_options
663- . as_ref ( )
664- . map ( |i| i. column_separator . clone ( ) )
665- . unwrap_or_else ( || {
663+ let col_sep_for_printing = column_mode_options. as_ref ( ) . map_or_else (
664+ || {
666665 merge_files_print
667666 . map ( |_k| DEFAULT_COLUMN_SEPARATOR . to_string ( ) )
668667 . unwrap_or_default ( )
669- } ) ;
668+ } ,
669+ |i| i. column_separator . clone ( ) ,
670+ ) ;
670671
671- let columns_to_print = merge_files_print
672- . unwrap_or_else ( || column_mode_options. as_ref ( ) . map ( |i| i. columns ) . unwrap_or ( 1 ) ) ;
672+ let columns_to_print =
673+ merge_files_print . unwrap_or_else ( || column_mode_options. as_ref ( ) . map_or ( 1 , |i| i. columns ) ) ;
673674
674675 let line_width = if join_lines {
675676 None
676677 } else if columns_to_print > 1 {
677678 Some (
678679 column_mode_options
679680 . as_ref ( )
680- . map ( |i| i. width )
681- . unwrap_or ( DEFAULT_COLUMN_WIDTH ) ,
681+ . map_or ( DEFAULT_COLUMN_WIDTH , |i| i. width ) ,
682682 )
683683 } else {
684684 page_width
@@ -712,8 +712,13 @@ fn open(path: &str) -> Result<Box<dyn Read>, PrError> {
712712 return Ok ( Box :: new ( stdin) as Box < dyn Read > ) ;
713713 }
714714
715- metadata ( path)
716- . map ( |i| {
715+ metadata ( path) . map_or_else (
716+ |_| {
717+ Err ( PrError :: NotExists {
718+ file : path. to_string ( ) ,
719+ } )
720+ } ,
721+ |i| {
717722 let path_string = path. to_string ( ) ;
718723 match i. file_type ( ) {
719724 #[ cfg( unix) ]
@@ -733,17 +738,19 @@ fn open(path: &str) -> Result<Box<dyn Read>, PrError> {
733738 }
734739 _ => Err ( PrError :: UnknownFiletype { file : path_string } ) ,
735740 }
736- } )
737- . unwrap_or_else ( |_| {
738- Err ( PrError :: NotExists {
739- file : path. to_string ( ) ,
740- } )
741- } )
741+ } ,
742+ )
742743}
743744
744745fn split_lines_if_form_feed ( file_content : Result < String , std:: io:: Error > ) -> Vec < FileLine > {
745- file_content
746- . map ( |content| {
746+ file_content. map_or_else (
747+ |e| {
748+ vec ! [ FileLine {
749+ line_content: Err ( e) ,
750+ ..FileLine :: default ( )
751+ } ]
752+ } ,
753+ |content| {
747754 let mut lines = Vec :: new ( ) ;
748755 let mut f_occurred = 0 ;
749756 let mut chunk = Vec :: new ( ) ;
@@ -772,13 +779,8 @@ fn split_lines_if_form_feed(file_content: Result<String, std::io::Error>) -> Vec
772779 } ) ;
773780
774781 lines
775- } )
776- . unwrap_or_else ( |e| {
777- vec ! [ FileLine {
778- line_content: Err ( e) ,
779- ..FileLine :: default ( )
780- } ]
781- } )
782+ } ,
783+ )
782784}
783785
784786fn pr ( path : & str , options : & OutputOptions ) -> Result < i32 , PrError > {
@@ -975,8 +977,7 @@ fn write_columns(
975977 let across_mode = options
976978 . column_mode_options
977979 . as_ref ( )
978- . map ( |i| i. across_mode )
979- . unwrap_or ( false ) ;
980+ . is_some_and ( |i| i. across_mode ) ;
980981
981982 let mut filled_lines = Vec :: new ( ) ;
982983 if options. merge_files_print . is_some ( ) {
@@ -1165,7 +1166,7 @@ fn trailer_content(options: &OutputOptions) -> Vec<String> {
11651166/// If -N is specified the first line number changes otherwise
11661167/// default is 1.
11671168fn get_start_line_number ( opts : & OutputOptions ) -> usize {
1168- opts. number . as_ref ( ) . map ( |i| i. first_number ) . unwrap_or ( 1 )
1169+ opts. number . as_ref ( ) . map_or ( 1 , |i| i. first_number )
11691170}
11701171
11711172/// Returns number of lines to read from input for constructing one page of pr output.
@@ -1183,8 +1184,5 @@ fn lines_to_read_for_page(opts: &OutputOptions) -> usize {
11831184
11841185/// Returns number of columns to output
11851186fn get_columns ( opts : & OutputOptions ) -> usize {
1186- opts. column_mode_options
1187- . as_ref ( )
1188- . map ( |i| i. columns )
1189- . unwrap_or ( 1 )
1187+ opts. column_mode_options . as_ref ( ) . map_or ( 1 , |i| i. columns )
11901188}
0 commit comments