@@ -62,7 +62,7 @@ impl RepoRaider {
6262 /// Checks out a branch in all directories that are repos
6363 pub fn checkout_branch ( & mut self , pattern : & str ) {
6464 let re = Regex :: new ( pattern) . expect ( "Error compiling regex" ) ;
65- for dir in & mut self . dirs {
65+ self . dirs . iter_mut ( ) . for_each ( |dir| {
6666 if let Some ( repo) = & dir. repo {
6767 println ! ( "Repo {}" , & dir. relative_path. display( ) ) ;
6868 let branches = git:: get_branches ( repo) . expect ( " ERROR unwrapping repo's Branches" ) ;
@@ -88,13 +88,13 @@ impl RepoRaider {
8888 } else {
8989 println ! ( " WARNING: folder is not a repository" ) ;
9090 }
91- }
91+ } ) ;
9292 }
9393
9494 /// Recursively matches for filenames with a specific name
9595 /// and saves them as a vector of Page structs
9696 pub fn match_files ( & mut self , pattern : & str ) {
97- for dir in & mut self . dirs {
97+ self . dirs . iter_mut ( ) . for_each ( |dir| {
9898 let f: Vec < structs:: Page > =
9999 func:: find_files ( dir. path . to_str ( ) . expect ( "Error unwrapping Path" ) , pattern)
100100 . iter ( )
@@ -108,15 +108,16 @@ impl RepoRaider {
108108 } )
109109 . collect ( ) ;
110110 dir. pages . extend ( f) ;
111- }
111+ } ) ;
112112 }
113113
114114 /// Recursively searches for all lines matching a pattern in a file
115115 /// and saves them as a vector of Match structs
116116 pub fn match_lines ( & mut self , pattern : & str ) {
117117 let re = Regex :: new ( pattern) . expect ( "Error compiling regex" ) ;
118- for dir in & mut self . dirs {
119- for page in & mut dir. pages {
118+ self . dirs . iter_mut ( ) . for_each ( |dir| {
119+ dir. pages . iter_mut ( ) . for_each ( |page| {
120+ // Open File
120121 let file = fs:: File :: open ( & page. path ) . expect ( "Error reading file" ) ;
121122
122123 // Create a buffered reader and loop through file's lines
@@ -142,28 +143,28 @@ impl RepoRaider {
142143 }
143144 }
144145 }
145- }
146- }
146+ } ) ;
147+ } ) ;
147148 }
148149
149150 /// Creates a replace string for Match struct
150151 pub fn replace ( & mut self , select : & str , replace : & str ) {
151152 let re = Regex :: new ( select) . expect ( "Error compiling regex" ) ;
152- for dir in & mut self . dirs {
153- for page in & mut dir. pages {
154- for mat in & mut page. matches {
153+ self . dirs . iter_mut ( ) . for_each ( |dir| {
154+ dir. pages . iter_mut ( ) . for_each ( |page| {
155+ page. matches . iter_mut ( ) . for_each ( |mat| {
155156 let res = re. replace ( mat. content . as_str ( ) , replace) ;
156157 mat. replace = Some ( res. to_string ( ) ) ;
157- }
158- }
159- }
158+ } ) ;
159+ } ) ;
160+ } ) ;
160161 }
161162
162163 /// Apply replace pattern to all Match structs
163164 /// for every Page struct in every Directory struct
164165 pub fn apply ( & mut self ) {
165- for dir in & mut self . dirs {
166- for page in & mut dir. pages {
166+ self . dirs . iter_mut ( ) . for_each ( |dir| {
167+ dir. pages . iter_mut ( ) . for_each ( |page| {
167168 // Open file with buffered reader
168169 let mut file =
169170 BufReader :: new ( fs:: File :: open ( & page. path ) . expect ( "Error opening file" ) ) ;
@@ -191,13 +192,13 @@ impl RepoRaider {
191192
192193 file. write_all ( file_contents. as_bytes ( ) )
193194 . expect ( "Error writing to file" ) ;
194- }
195- }
195+ } ) ;
196+ } ) ;
196197 }
197198
198199 /// Stage all matches
199200 pub fn stage ( & mut self ) {
200- for dir in & mut self . dirs {
201+ self . dirs . iter_mut ( ) . for_each ( |dir| {
201202 if let Some ( repo) = & mut dir. repo {
202203 // Stage all changes
203204 // TODO: Only stage matched files
@@ -208,12 +209,12 @@ impl RepoRaider {
208209 dir. relative_path. display( )
209210 ) ;
210211 }
211- }
212+ } ) ;
212213 }
213214
214215 /// Commit all matches
215216 pub fn commit ( & mut self , msg : & str ) {
216- for dir in & mut self . dirs {
217+ self . dirs . iter_mut ( ) . for_each ( |dir| {
217218 if let Some ( repo) = & mut dir. repo {
218219 // Commit all staged files
219220 git:: commit ( repo, msg) . expect ( "Error committing changes" ) ;
@@ -223,7 +224,7 @@ impl RepoRaider {
223224 dir. relative_path. display( )
224225 ) ;
225226 }
226- }
227+ } ) ;
227228 }
228229
229230 /// Gets all folders
@@ -293,11 +294,10 @@ mod tests {
293294 raider. match_files ( "main.rs" ) ;
294295 assert_ne ! ( raider. get_pages( ) . len( ) , 0 ) ;
295296
296- let pages = raider. get_pages ( ) ;
297- for page in pages {
297+ raider. get_pages ( ) . iter ( ) . for_each ( |page| {
298298 assert ! ( page. path. to_string_lossy( ) . contains( "main.rs" ) ) ;
299299 assert ! ( page. relative_path. to_string_lossy( ) . contains( "main.rs" ) ) ;
300- }
300+ } ) ;
301301 }
302302
303303 #[ test]
@@ -309,9 +309,8 @@ mod tests {
309309 raider. match_files ( "main.rs" ) ;
310310 raider. match_lines ( "RepoRaider" ) ;
311311
312- let mat = raider. get_matches ( ) ;
313- for m in mat {
312+ raider. get_matches ( ) . iter ( ) . for_each ( |m| {
314313 assert ! ( m. content. contains( "RepoRaider" ) ) ;
315- }
314+ } ) ;
316315 }
317316}
0 commit comments