@@ -156,7 +156,7 @@ fn rubyfmt_string(
156156 ..
157157 } : & CommandlineOpts ,
158158 buffer : & str ,
159- ) -> Result < Option < String > , rubyfmt:: RichFormatError > {
159+ ) -> Result < Option < Vec < u8 > > , rubyfmt:: RichFormatError > {
160160 if header_opt_in || header_opt_out {
161161 // Only look at the first 500 bytes for the magic header.
162162 // This is for performance
@@ -282,7 +282,7 @@ fn iterate_input_files(opts: &CommandlineOpts, f: &dyn Fn((&Path, &String))) {
282282 if is_path_ignored ( path, opts. include_gitignored ) {
283283 // Print unchanged output for ignored files unless we're in check mode
284284 if !opts. check {
285- puts_stdout ( & buffer) ;
285+ puts_stdout ( buffer. as_bytes ( ) ) ;
286286 }
287287 return ;
288288 }
@@ -350,7 +350,7 @@ fn iterate_input_files(opts: &CommandlineOpts, f: &dyn Fn((&Path, &String))) {
350350 }
351351}
352352
353- type FormattingFunc < ' a > = & ' a dyn Fn ( ( & Path , & String , Option < String > ) ) ;
353+ type FormattingFunc < ' a > = & ' a dyn Fn ( ( & Path , & String , Option < Vec < u8 > > ) ) ;
354354
355355fn iterate_formatted ( opts : & CommandlineOpts , f : FormattingFunc ) {
356356 iterate_input_files (
@@ -365,9 +365,9 @@ fn iterate_formatted(opts: &CommandlineOpts, f: FormattingFunc) {
365365 ) ;
366366}
367367
368- fn puts_stdout ( input : & String ) {
368+ fn puts_stdout ( input : & [ u8 ] ) {
369369 io:: stdout ( )
370- . write_all ( input. as_bytes ( ) )
370+ . write_all ( input)
371371 . expect ( "Could not write to stdout" ) ;
372372 io:: stdout ( ) . flush ( ) . expect ( "flush works" ) ;
373373}
@@ -392,7 +392,7 @@ fn main() {
392392 & |( file_path, before) | match rubyfmt_string ( & opts, before) {
393393 Ok ( None ) => { }
394394 Ok ( Some ( fmtted) ) => {
395- let diff = TextDiff :: from_lines ( before, & fmtted) ;
395+ let diff = TextDiff :: from_lines ( before. as_bytes ( ) , & fmtted) ;
396396 let path_string = file_path. to_str ( ) . unwrap ( ) ;
397397 text_diffs. lock ( ) . unwrap ( ) . push ( format ! (
398398 "{}" ,
@@ -416,7 +416,7 @@ fn main() {
416416
417417 for diff in all_diffs. iter ( ) {
418418 if !diff. is_empty ( ) {
419- puts_stdout ( diff) ;
419+ puts_stdout ( diff. as_bytes ( ) ) ;
420420 diffs_reported += 1
421421 }
422422 }
@@ -434,12 +434,12 @@ fn main() {
434434 iterate_formatted ( & opts, & |( file_path, before, after) | match after {
435435 None => { }
436436 Some ( fmtted) => {
437- if fmtted. ne ( before) {
437+ if fmtted. ne ( before. as_bytes ( ) ) {
438438 let file_write = OpenOptions :: new ( )
439439 . write ( true )
440440 . truncate ( true )
441441 . open ( file_path)
442- . and_then ( |mut file| file. write_all ( fmtted. as_bytes ( ) ) ) ;
442+ . and_then ( |mut file| file. write_all ( & fmtted) ) ;
443443
444444 match file_write {
445445 Ok ( _) => { }
@@ -455,7 +455,7 @@ fn main() {
455455
456456 _ => iterate_formatted ( & opts, & |( _, before, after) | match after {
457457 Some ( fmtted) => puts_stdout ( & fmtted) ,
458- None => puts_stdout ( before) ,
458+ None => puts_stdout ( before. as_bytes ( ) ) ,
459459 } ) ,
460460 }
461461}
0 commit comments