@@ -2,13 +2,14 @@ use std::borrow::Cow;
2
2
3
3
use bstr:: BStr ;
4
4
5
- use crate :: { file:: MetadataFilter , value, AsKey , File } ;
5
+ use crate :: file:: Metadata ;
6
+ use crate :: { value, AsKey , File } ;
6
7
7
8
/// Comfortable API for accessing values
8
9
impl File < ' _ > {
9
10
/// Like [`string_by()`](File::string_by()), but suitable for statically known `key`s like `remote.origin.url`.
10
11
pub fn string ( & self , key : impl AsKey ) -> Option < Cow < ' _ , BStr > > {
11
- self . string_filter ( key, & mut |_| true )
12
+ self . string_filter ( key, |_| true )
12
13
}
13
14
14
15
/// Like [`value()`](File::value()), but returning `None` if the string wasn't found.
@@ -20,13 +21,11 @@ impl File<'_> {
20
21
subsection_name : Option < & BStr > ,
21
22
value_name : impl AsRef < str > ,
22
23
) -> Option < Cow < ' _ , BStr > > {
23
- self . string_filter_by ( section_name. as_ref ( ) , subsection_name, value_name. as_ref ( ) , & mut |_| {
24
- true
25
- } )
24
+ self . string_filter_by ( section_name. as_ref ( ) , subsection_name, value_name. as_ref ( ) , |_| true )
26
25
}
27
26
28
27
/// Like [`string_filter_by()`](File::string_filter_by()), but suitable for statically known `key`s like `remote.origin.url`.
29
- pub fn string_filter ( & self , key : impl AsKey , filter : & mut MetadataFilter ) -> Option < Cow < ' _ , BStr > > {
28
+ pub fn string_filter ( & self , key : impl AsKey , filter : impl FnMut ( & Metadata ) -> bool ) -> Option < Cow < ' _ , BStr > > {
30
29
let key = key. try_as_key ( ) ?;
31
30
self . raw_value_filter_by ( key. section_name , key. subsection_name , key. value_name , filter)
32
31
. ok ( )
@@ -38,15 +37,15 @@ impl File<'_> {
38
37
section_name : impl AsRef < str > ,
39
38
subsection_name : Option < & BStr > ,
40
39
value_name : impl AsRef < str > ,
41
- filter : & mut MetadataFilter ,
40
+ filter : impl FnMut ( & Metadata ) -> bool ,
42
41
) -> Option < Cow < ' _ , BStr > > {
43
42
self . raw_value_filter_by ( section_name. as_ref ( ) , subsection_name, value_name. as_ref ( ) , filter)
44
43
. ok ( )
45
44
}
46
45
47
46
/// Like [`path_by()`](File::path_by()), but suitable for statically known `key`s like `remote.origin.url`.
48
47
pub fn path ( & self , key : impl AsKey ) -> Option < crate :: Path < ' _ > > {
49
- self . path_filter ( key, & mut |_| true )
48
+ self . path_filter ( key, |_| true )
50
49
}
51
50
52
51
/// Like [`value()`](File::value()), but returning `None` if the path wasn't found.
@@ -61,13 +60,11 @@ impl File<'_> {
61
60
subsection_name : Option < & BStr > ,
62
61
value_name : impl AsRef < str > ,
63
62
) -> Option < crate :: Path < ' _ > > {
64
- self . path_filter_by ( section_name. as_ref ( ) , subsection_name, value_name. as_ref ( ) , & mut |_| {
65
- true
66
- } )
63
+ self . path_filter_by ( section_name. as_ref ( ) , subsection_name, value_name. as_ref ( ) , |_| true )
67
64
}
68
65
69
66
/// Like [`path_filter_by()`](File::path_filter_by()), but suitable for statically known `key`s like `remote.origin.url`.
70
- pub fn path_filter ( & self , key : impl AsKey , filter : & mut MetadataFilter ) -> Option < crate :: Path < ' _ > > {
67
+ pub fn path_filter ( & self , key : impl AsKey , filter : impl FnMut ( & Metadata ) -> bool ) -> Option < crate :: Path < ' _ > > {
71
68
let key = key. try_as_key ( ) ?;
72
69
self . path_filter_by ( key. section_name , key. subsection_name , key. value_name , filter)
73
70
}
@@ -83,7 +80,7 @@ impl File<'_> {
83
80
section_name : impl AsRef < str > ,
84
81
subsection_name : Option < & BStr > ,
85
82
value_name : impl AsRef < str > ,
86
- filter : & mut MetadataFilter ,
83
+ filter : impl FnMut ( & Metadata ) -> bool ,
87
84
) -> Option < crate :: Path < ' _ > > {
88
85
self . raw_value_filter_by ( section_name. as_ref ( ) , subsection_name, value_name. as_ref ( ) , filter)
89
86
. ok ( )
@@ -92,7 +89,7 @@ impl File<'_> {
92
89
93
90
/// Like [`boolean_by()`](File::boolean_by()), but suitable for statically known `key`s like `remote.origin.url`.
94
91
pub fn boolean ( & self , key : impl AsKey ) -> Option < Result < bool , value:: Error > > {
95
- self . boolean_filter ( key, & mut |_| true )
92
+ self . boolean_filter ( key, |_| true )
96
93
}
97
94
98
95
/// Like [`value()`](File::value()), but returning `None` if the boolean value wasn't found.
@@ -102,13 +99,15 @@ impl File<'_> {
102
99
subsection_name : Option < & BStr > ,
103
100
value_name : impl AsRef < str > ,
104
101
) -> Option < Result < bool , value:: Error > > {
105
- self . boolean_filter_by ( section_name. as_ref ( ) , subsection_name, value_name. as_ref ( ) , & mut |_| {
106
- true
107
- } )
102
+ self . boolean_filter_by ( section_name. as_ref ( ) , subsection_name, value_name. as_ref ( ) , |_| true )
108
103
}
109
104
110
105
/// Like [`boolean_filter_by()`](File::boolean_filter_by()), but suitable for statically known `key`s like `remote.origin.url`.
111
- pub fn boolean_filter ( & self , key : impl AsKey , filter : & mut MetadataFilter ) -> Option < Result < bool , value:: Error > > {
106
+ pub fn boolean_filter (
107
+ & self ,
108
+ key : impl AsKey ,
109
+ filter : impl FnMut ( & Metadata ) -> bool ,
110
+ ) -> Option < Result < bool , value:: Error > > {
112
111
let key = key. try_as_key ( ) ?;
113
112
self . boolean_filter_by ( key. section_name , key. subsection_name , key. value_name , filter)
114
113
}
@@ -119,7 +118,7 @@ impl File<'_> {
119
118
section_name : impl AsRef < str > ,
120
119
subsection_name : Option < & BStr > ,
121
120
value_name : impl AsRef < str > ,
122
- filter : & mut MetadataFilter ,
121
+ mut filter : impl FnMut ( & Metadata ) -> bool ,
123
122
) -> Option < Result < bool , value:: Error > > {
124
123
let section_name = section_name. as_ref ( ) ;
125
124
let section_ids = self
@@ -142,7 +141,7 @@ impl File<'_> {
142
141
143
142
/// Like [`integer_by()`](File::integer_by()), but suitable for statically known `key`s like `remote.origin.url`.
144
143
pub fn integer ( & self , key : impl AsKey ) -> Option < Result < i64 , value:: Error > > {
145
- self . integer_filter ( key, & mut |_| true )
144
+ self . integer_filter ( key, |_| true )
146
145
}
147
146
148
147
/// Like [`value()`](File::value()), but returning an `Option` if the integer wasn't found.
@@ -152,11 +151,15 @@ impl File<'_> {
152
151
subsection_name : Option < & BStr > ,
153
152
value_name : impl AsRef < str > ,
154
153
) -> Option < Result < i64 , value:: Error > > {
155
- self . integer_filter_by ( section_name, subsection_name, value_name, & mut |_| true )
154
+ self . integer_filter_by ( section_name, subsection_name, value_name, |_| true )
156
155
}
157
156
158
157
/// Like [`integer_filter_by()`](File::integer_filter_by()), but suitable for statically known `key`s like `remote.origin.url`.
159
- pub fn integer_filter ( & self , key : impl AsKey , filter : & mut MetadataFilter ) -> Option < Result < i64 , value:: Error > > {
158
+ pub fn integer_filter (
159
+ & self ,
160
+ key : impl AsKey ,
161
+ filter : impl FnMut ( & Metadata ) -> bool ,
162
+ ) -> Option < Result < i64 , value:: Error > > {
160
163
let key = key. try_as_key ( ) ?;
161
164
self . integer_filter_by ( key. section_name , key. subsection_name , key. value_name , filter)
162
165
}
@@ -167,7 +170,7 @@ impl File<'_> {
167
170
section_name : impl AsRef < str > ,
168
171
subsection_name : Option < & BStr > ,
169
172
value_name : impl AsRef < str > ,
170
- filter : & mut MetadataFilter ,
173
+ filter : impl FnMut ( & Metadata ) -> bool ,
171
174
) -> Option < Result < i64 , value:: Error > > {
172
175
let int = self
173
176
. raw_value_filter_by ( section_name. as_ref ( ) , subsection_name, value_name. as_ref ( ) , filter)
@@ -196,7 +199,7 @@ impl File<'_> {
196
199
}
197
200
198
201
/// Like [`strings_filter_by()`](File::strings_filter_by()), but suitable for statically known `key`s like `remote.origin.url`.
199
- pub fn strings_filter ( & self , key : impl AsKey , filter : & mut MetadataFilter ) -> Option < Vec < Cow < ' _ , BStr > > > {
202
+ pub fn strings_filter ( & self , key : impl AsKey , filter : impl FnMut ( & Metadata ) -> bool ) -> Option < Vec < Cow < ' _ , BStr > > > {
200
203
let key = key. try_as_key ( ) ?;
201
204
self . strings_filter_by ( key. section_name , key. subsection_name , key. value_name , filter)
202
205
}
@@ -207,15 +210,15 @@ impl File<'_> {
207
210
section_name : impl AsRef < str > ,
208
211
subsection_name : Option < & BStr > ,
209
212
value_name : impl AsRef < str > ,
210
- filter : & mut MetadataFilter ,
213
+ filter : impl FnMut ( & Metadata ) -> bool ,
211
214
) -> Option < Vec < Cow < ' _ , BStr > > > {
212
215
self . raw_values_filter_by ( section_name. as_ref ( ) , subsection_name, value_name. as_ref ( ) , filter)
213
216
. ok ( )
214
217
}
215
218
216
219
/// Like [`integers()`](File::integers()), but suitable for statically known `key`s like `remote.origin.url`.
217
220
pub fn integers ( & self , key : impl AsKey ) -> Option < Result < Vec < i64 > , value:: Error > > {
218
- self . integers_filter ( key, & mut |_| true )
221
+ self . integers_filter ( key, |_| true )
219
222
}
220
223
221
224
/// Similar to [`values_by(…)`](File::values_by()) but returning integers if at least one of them was found
@@ -226,16 +229,14 @@ impl File<'_> {
226
229
subsection_name : Option < & BStr > ,
227
230
value_name : impl AsRef < str > ,
228
231
) -> Option < Result < Vec < i64 > , value:: Error > > {
229
- self . integers_filter_by ( section_name. as_ref ( ) , subsection_name, value_name. as_ref ( ) , & mut |_| {
230
- true
231
- } )
232
+ self . integers_filter_by ( section_name. as_ref ( ) , subsection_name, value_name. as_ref ( ) , |_| true )
232
233
}
233
234
234
235
/// Like [`integers_filter_by()`](File::integers_filter_by()), but suitable for statically known `key`s like `remote.origin.url`.
235
236
pub fn integers_filter (
236
237
& self ,
237
238
key : impl AsKey ,
238
- filter : & mut MetadataFilter ,
239
+ filter : impl FnMut ( & Metadata ) -> bool ,
239
240
) -> Option < Result < Vec < i64 > , value:: Error > > {
240
241
let key = key. try_as_key ( ) ?;
241
242
self . integers_filter_by ( key. section_name , key. subsection_name , key. value_name , filter)
@@ -248,7 +249,7 @@ impl File<'_> {
248
249
section_name : impl AsRef < str > ,
249
250
subsection_name : Option < & BStr > ,
250
251
value_name : impl AsRef < str > ,
251
- filter : & mut MetadataFilter ,
252
+ filter : impl FnMut ( & Metadata ) -> bool ,
252
253
) -> Option < Result < Vec < i64 > , value:: Error > > {
253
254
self . raw_values_filter_by ( section_name. as_ref ( ) , subsection_name, value_name. as_ref ( ) , filter)
254
255
. ok ( )
0 commit comments