File tree Expand file tree Collapse file tree 1 file changed +8
-19
lines changed Expand file tree Collapse file tree 1 file changed +8
-19
lines changed Original file line number Diff line number Diff line change @@ -48,28 +48,17 @@ pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
48
48
}
49
49
50
50
pub fn search < ' a > ( query : & str , contents : & ' a str ) -> Vec < & ' a str > {
51
- let mut results = Vec :: new ( ) ;
52
-
53
- for line in contents. lines ( ) {
54
- if line. contains ( query) {
55
- results. push ( line) ;
56
- }
57
- }
58
-
59
- results
51
+ contents. lines ( )
52
+ . filter ( |line| line. contains ( query) )
53
+ . collect ( )
60
54
}
61
55
62
56
pub fn search_case_insensitive < ' b > ( query : & str , contents : & ' b str ) -> Vec < & ' b str > {
63
- let query = query. to_lowercase ( ) ;
64
- let mut results = Vec :: new ( ) ;
65
-
66
- for line in contents. lines ( ) {
67
- if line. to_lowercase ( ) . contains ( & query) {
68
- results. push ( line) ;
69
- }
70
- }
71
-
72
- results
57
+ let lower_query = query. to_lowercase ( ) ;
58
+ contents
59
+ . lines ( )
60
+ . filter ( |line : & & ' b str | line. to_lowercase ( ) . contains ( & lower_query) )
61
+ . collect ( )
73
62
}
74
63
75
64
#[ cfg( test) ]
You can’t perform that action at this time.
0 commit comments