@@ -43,43 +43,40 @@ fn should_combine_code_blocks(path: &Path) -> io::Result<bool> {
4343 Ok ( buf. trim_ascii_end ( ) . ends_with ( FLAG ) )
4444}
4545
46- fn apply_diff ( src : & mut String , preamble : & str , added : & str , removed : & str )
47- -> Result
48- {
46+ fn apply_diff ( src : & mut String , preamble : & str , added : & str , removed : & str ) -> Result {
4947 assert ! (
5048 !preamble. is_empty( ) || !removed. is_empty( ) ,
51- "Failure on applying a diff: \n \
52- No preamble or text to remove provided, unable to find location to insert:\n {added}\n \
53- In the following text:\n {src}",
49+ "Failure on applying a diff: \n No preamble or text to remove provided, unable to find \
50+ location to insert:\n {added}\n In the following text:\n {src}",
5451 ) ;
5552
5653 let mut matches = src. match_indices ( if preamble. is_empty ( ) {
5754 removed
5855 } else {
59- & preamble
56+ preamble
6057 } ) ;
6158 let Some ( ( preamble_start, _) ) = matches. next ( ) else {
62- e ! ( "Failure on applying a diff: \n \
63- couldn't find the following text:\n {preamble}\n \n In the following text:\n {src}")
59+ e ! (
60+ "Failure on applying a diff: \n couldn't find the following text:\n {preamble}\n \n In \
61+ the following text:\n {src}"
62+ )
6463 } ;
65-
64+
6665 assert ! (
6766 matches. next( ) . is_none( ) ,
68- "Failure on applying a diff: \n \
69- Ambiguous preamble:\n {preamble}\n \
70- In the following text:\n {src}\n \
71- While trying to remove the following text:\n {removed}\n \
72- And add the following:\n {added}\n "
67+ "Failure on applying a diff: \n Ambiguous preamble:\n {preamble}\n In the following \
68+ text:\n {src}\n While trying to remove the following text:\n {removed}\n And add the \
69+ following:\n {added}\n "
7370 ) ;
7471
7572 let preamble_end = preamble_start + preamble. len ( ) ;
7673 assert ! (
77- src. get( preamble_end .. preamble_end + removed. len( ) ) == Some ( removed) ,
78- "Failure on applying a diff: \n \
79- Text to remove not found: \n {removed} \n \n In the following text:\n {src}",
74+ src. get( preamble_end.. preamble_end + removed. len( ) ) == Some ( removed) ,
75+ "Failure on applying a diff: \n Text to remove not found: \n {removed} \n \n In the following \
76+ text:\n {src}",
8077 ) ;
8178
82- src. replace_range ( preamble_end .. preamble_end + removed. len ( ) , added) ;
79+ src. replace_range ( preamble_end.. preamble_end + removed. len ( ) , added) ;
8380 Ok ( ( ) )
8481}
8582
@@ -88,10 +85,10 @@ fn combined_code_blocks(path: &Path) -> Result<String> {
8885 let mut res = String :: new ( ) ;
8986
9087 let mut err = Ok ( ( ) ) ;
91- let mut lines = file. lines ( ) . filter_map ( |i| {
92- i . map_err ( |e| err = Err ( e ) ) . ok ( )
93- } ) . enumerate ( ) ;
94- while let Some ( ( i , line) ) = lines. next ( ) {
88+ let mut lines = file
89+ . lines ( )
90+ . filter_map ( |i| i . map_err ( |e| err = Err ( e ) ) . ok ( ) ) ;
91+ while let Some ( line) = lines. next ( ) {
9592 if !line. starts_with ( "```rust" ) {
9693 continue ;
9794 }
@@ -100,13 +97,12 @@ fn combined_code_blocks(path: &Path) -> Result<String> {
10097 let mut added = String :: new ( ) ;
10198 let mut removed = String :: new ( ) ;
10299 let mut diff_applied = false ;
103- for ( i , line) in & mut lines {
100+ for line in & mut lines {
104101 if line. starts_with ( "```" ) {
105102 if !added. is_empty ( ) || !removed. is_empty ( ) {
106- apply_diff ( & mut res, & preamble, & added, & removed)
107- . inspect_err ( |_| eprintln ! ( "Line {i}" ) ) ?;
108- } else if !diff_applied { // if no diff markers were found, just add the contents
109- eprintln ! ( "Shrimply added {preamble:?}, line {i}" ) ;
103+ apply_diff ( & mut res, & preamble, & added, & removed) ?;
104+ } else if !diff_applied {
105+ // if no diff markers were found, just add the contents
110106 res += & preamble;
111107 }
112108 break ;
@@ -122,13 +118,13 @@ fn combined_code_blocks(path: &Path) -> Result<String> {
122118 }
123119 removed += line;
124120 removed += "\n " ;
125- } else if line. trim_ascii ( ) == "// ..." { // disregard the preamble
121+ } else if line. trim_ascii ( ) == "// ..." {
122+ // disregard the preamble
126123 preamble. clear ( ) ;
127124 } else {
128125 if !added. is_empty ( ) || !removed. is_empty ( ) {
129126 diff_applied = true ;
130- apply_diff ( & mut res, & preamble, & added, & removed)
131- . inspect_err ( |_| eprintln ! ( "Line {i}" ) ) ?;
127+ apply_diff ( & mut res, & preamble, & added, & removed) ?;
132128 preamble += & added;
133129 added. clear ( ) ;
134130 removed. clear ( ) ;
@@ -233,7 +229,10 @@ fn inner_main() -> Result {
233229 let mut parts = vec ! [ ] ;
234230
235231 for part in rel {
236- parts. push ( part. to_str ( ) . ok_or_else ( || format ! ( "Non-UTF8 path: {rel:?}" ) ) ?) ;
232+ parts. push (
233+ part. to_str ( )
234+ . ok_or_else ( || format ! ( "Non-UTF8 path: {rel:?}" ) ) ?,
235+ ) ;
237236 }
238237
239238 level. insert ( path. clone ( ) , & parts[ ..] ) ;
0 commit comments