@@ -2,29 +2,29 @@ use std::{borrow::Cow, convert::TryFrom};
2
2
3
3
use bstr:: BStr ;
4
4
5
- use crate :: { file:: MetadataFilter , value, File } ;
5
+ use crate :: { file:: MetadataFilter , value, File , Key } ;
6
6
7
7
/// Comfortable API for accessing values
8
8
impl < ' event > File < ' event > {
9
9
/// Like [`value()`][File::value()], but returning `None` if the string wasn't found.
10
10
///
11
11
/// As strings perform no conversions, this will never fail.
12
- pub fn string (
12
+ pub fn string_by (
13
13
& self ,
14
14
section_name : impl AsRef < str > ,
15
15
subsection_name : Option < & BStr > ,
16
16
key : impl AsRef < str > ,
17
17
) -> Option < Cow < ' _ , BStr > > {
18
- self . string_filter ( section_name, subsection_name, key, & mut |_| true )
18
+ self . string_filter_by ( section_name, subsection_name, key, & mut |_| true )
19
19
}
20
20
21
- /// Like [`string()`][File::string ()], but suitable for statically known `key`s like `remote.origin.url`.
22
- pub fn string_by_key < ' a > ( & self , key : impl Into < & ' a BStr > ) -> Option < Cow < ' _ , BStr > > {
23
- self . string_filter_by_key ( key, & mut |_| true )
21
+ /// Like [`string()`][File::string_by ()], but suitable for statically known `key`s like `remote.origin.url`.
22
+ pub fn string ( & self , key : impl Key ) -> Option < Cow < ' _ , BStr > > {
23
+ self . string_filter ( key, & mut |_| true )
24
24
}
25
25
26
26
/// Like [`string()`][File::string()], but the section containing the returned value must pass `filter` as well.
27
- pub fn string_filter (
27
+ pub fn string_filter_by (
28
28
& self ,
29
29
section_name : impl AsRef < str > ,
30
30
subsection_name : Option < & BStr > ,
@@ -35,14 +35,13 @@ impl<'event> File<'event> {
35
35
. ok ( )
36
36
}
37
37
38
- /// Like [`string_filter()`][File::string_filter ()], but suitable for statically known `key`s like `remote.origin.url`.
39
- pub fn string_filter_by_key < ' a > (
38
+ /// Like [`string_filter()`][File::string_filter_by ()], but suitable for statically known `key`s like `remote.origin.url`.
39
+ pub fn string_filter (
40
40
& self ,
41
- key : impl Into < & ' a BStr > ,
41
+ key : impl Key ,
42
42
filter : & mut MetadataFilter ,
43
43
) -> Option < Cow < ' _ , BStr > > {
44
- let key = crate :: parse:: key ( key. into ( ) ) ?;
45
- self . raw_value_filter ( key. section_name , key. subsection_name , key. value_name , filter)
44
+ self . raw_value_filter ( key. section_name ( ) , key. subsection_name ( ) , key. name ( ) , filter)
46
45
. ok ( )
47
46
}
48
47
@@ -52,18 +51,18 @@ impl<'event> File<'event> {
52
51
/// to pose a security risk. Prefer using [`path_filter()`][File::path_filter()] instead.
53
52
///
54
53
/// As paths perform no conversions, this will never fail.
55
- pub fn path (
54
+ pub fn path_by (
56
55
& self ,
57
56
section_name : impl AsRef < str > ,
58
57
subsection_name : Option < & BStr > ,
59
58
key : impl AsRef < str > ,
60
59
) -> Option < crate :: Path < ' _ > > {
61
- self . path_filter ( section_name, subsection_name, key, & mut |_| true )
60
+ self . path_filter_by ( section_name, subsection_name, key, & mut |_| true )
62
61
}
63
62
64
- /// Like [`path()`][File::path ()], but suitable for statically known `key`s like `remote.origin.url`.
65
- pub fn path_by_key < ' a > ( & self , key : impl Into < & ' a BStr > ) -> Option < crate :: Path < ' _ > > {
66
- self . path_filter_by_key ( key, & mut |_| true )
63
+ /// Like [`path()`][File::path_by ()], but suitable for statically known `key`s like `remote.origin.url`.
64
+ pub fn path ( & self , key : impl Key ) -> Option < crate :: Path < ' _ > > {
65
+ self . path_filter ( key, & mut |_| true )
67
66
}
68
67
69
68
/// Like [`path()`][File::path()], but the section containing the returned value must pass `filter` as well.
@@ -72,7 +71,7 @@ impl<'event> File<'event> {
72
71
/// locations can be
73
72
///
74
73
/// As paths perform no conversions, this will never fail.
75
- pub fn path_filter (
74
+ pub fn path_filter_by (
76
75
& self ,
77
76
section_name : impl AsRef < str > ,
78
77
subsection_name : Option < & BStr > ,
@@ -84,33 +83,32 @@ impl<'event> File<'event> {
84
83
. map ( crate :: Path :: from)
85
84
}
86
85
87
- /// Like [`path_filter()`][File::path_filter ()], but suitable for statically known `key`s like `remote.origin.url`.
88
- pub fn path_filter_by_key < ' a > (
86
+ /// Like [`path_filter()`][File::path_filter_by ()], but suitable for statically known `key`s like `remote.origin.url`.
87
+ pub fn path_filter (
89
88
& self ,
90
- key : impl Into < & ' a BStr > ,
89
+ key : impl Key ,
91
90
filter : & mut MetadataFilter ,
92
91
) -> Option < crate :: Path < ' _ > > {
93
- let key = crate :: parse:: key ( key. into ( ) ) ?;
94
- self . path_filter ( key. section_name , key. subsection_name , key. value_name , filter)
92
+ self . path_filter_by ( key. section_name ( ) , key. subsection_name ( ) , key. name ( ) , filter)
95
93
}
96
94
97
95
/// Like [`value()`][File::value()], but returning `None` if the boolean value wasn't found.
98
- pub fn boolean (
96
+ pub fn boolean_by (
99
97
& self ,
100
98
section_name : impl AsRef < str > ,
101
99
subsection_name : Option < & BStr > ,
102
100
key : impl AsRef < str > ,
103
101
) -> Option < Result < bool , value:: Error > > {
104
- self . boolean_filter ( section_name, subsection_name, key, & mut |_| true )
102
+ self . boolean_filter_by ( section_name, subsection_name, key, & mut |_| true )
105
103
}
106
104
107
- /// Like [`boolean()`][File::boolean ()], but suitable for statically known `key`s like `remote.origin.url`.
108
- pub fn boolean_by_key < ' a > ( & self , key : impl Into < & ' a BStr > ) -> Option < Result < bool , value:: Error > > {
109
- self . boolean_filter_by_key ( key, & mut |_| true )
105
+ /// Like [`boolean()`][File::boolean_by ()], but suitable for statically known `key`s like `remote.origin.url`.
106
+ pub fn boolean ( & self , key : impl Key ) -> Option < Result < bool , value:: Error > > {
107
+ self . boolean_filter ( key, & mut |_| true )
110
108
}
111
109
112
- /// Like [`boolean()`][File::boolean ()], but the section containing the returned value must pass `filter` as well.
113
- pub fn boolean_filter (
110
+ /// Like [`boolean()`][File::boolean_by ()], but the section containing the returned value must pass `filter` as well.
111
+ pub fn boolean_filter_by (
114
112
& self ,
115
113
section_name : impl AsRef < str > ,
116
114
subsection_name : Option < & BStr > ,
@@ -136,33 +134,32 @@ impl<'event> File<'event> {
136
134
None
137
135
}
138
136
139
- /// Like [`boolean_filter()`][File::boolean_filter ()], but suitable for statically known `key`s like `remote.origin.url`.
140
- pub fn boolean_filter_by_key < ' a > (
137
+ /// Like [`boolean_filter()`][File::boolean_filter_by ()], but suitable for statically known `key`s like `remote.origin.url`.
138
+ pub fn boolean_filter (
141
139
& self ,
142
- key : impl Into < & ' a BStr > ,
140
+ key : impl Key ,
143
141
filter : & mut MetadataFilter ,
144
142
) -> Option < Result < bool , value:: Error > > {
145
- let key = crate :: parse:: key ( key. into ( ) ) ?;
146
- self . boolean_filter ( key. section_name , key. subsection_name , key. value_name , filter)
143
+ self . boolean_filter_by ( key. section_name ( ) , key. subsection_name ( ) , key. name ( ) , filter)
147
144
}
148
145
149
146
/// Like [`value()`][File::value()], but returning an `Option` if the integer wasn't found.
150
- pub fn integer (
147
+ pub fn integer_by (
151
148
& self ,
152
149
section_name : impl AsRef < str > ,
153
150
subsection_name : Option < & BStr > ,
154
151
key : impl AsRef < str > ,
155
152
) -> Option < Result < i64 , value:: Error > > {
156
- self . integer_filter ( section_name, subsection_name, key, & mut |_| true )
153
+ self . integer_filter_by ( section_name, subsection_name, key, & mut |_| true )
157
154
}
158
155
159
- /// Like [`integer()`][File::integer ()], but suitable for statically known `key`s like `remote.origin.url`.
160
- pub fn integer_by_key < ' a > ( & self , key : impl Into < & ' a BStr > ) -> Option < Result < i64 , value:: Error > > {
161
- self . integer_filter_by_key ( key, & mut |_| true )
156
+ /// Like [`integer()`][File::integer_by ()], but suitable for statically known `key`s like `remote.origin.url`.
157
+ pub fn integer ( & self , key : impl Key ) -> Option < Result < i64 , value:: Error > > {
158
+ self . integer_filter ( key, & mut |_| true )
162
159
}
163
160
164
- /// Like [`integer()`][File::integer ()], but the section containing the returned value must pass `filter` as well.
165
- pub fn integer_filter (
161
+ /// Like [`integer()`][File::integer_by ()], but the section containing the returned value must pass `filter` as well.
162
+ pub fn integer_filter_by (
166
163
& self ,
167
164
section_name : impl AsRef < str > ,
168
165
subsection_name : Option < & BStr > ,
@@ -178,35 +175,33 @@ impl<'event> File<'event> {
178
175
} ) )
179
176
}
180
177
181
- /// Like [`integer_filter()`][File::integer_filter ()], but suitable for statically known `key`s like `remote.origin.url`.
182
- pub fn integer_filter_by_key < ' a > (
178
+ /// Like [`integer_filter()`][File::integer_filter_by ()], but suitable for statically known `key`s like `remote.origin.url`.
179
+ pub fn integer_filter (
183
180
& self ,
184
- key : impl Into < & ' a BStr > ,
181
+ key : impl Key ,
185
182
filter : & mut MetadataFilter ,
186
183
) -> Option < Result < i64 , value:: Error > > {
187
- let key = crate :: parse:: key ( key. into ( ) ) ?;
188
- self . integer_filter ( key. section_name , key. subsection_name , key. value_name , filter)
184
+ self . integer_filter_by ( key. section_name ( ) , key. subsection_name ( ) , key. name ( ) , filter)
189
185
}
190
186
191
187
/// Similar to [`values(…)`][File::values()] but returning strings if at least one of them was found.
192
- pub fn strings (
188
+ pub fn strings_by (
193
189
& self ,
194
190
section_name : impl AsRef < str > ,
195
191
subsection_name : Option < & BStr > ,
196
192
key : impl AsRef < str > ,
197
193
) -> Option < Vec < Cow < ' _ , BStr > > > {
198
- self . raw_values ( section_name. as_ref ( ) , subsection_name, key. as_ref ( ) )
194
+ self . raw_values_by ( section_name. as_ref ( ) , subsection_name, key. as_ref ( ) )
199
195
. ok ( )
200
196
}
201
197
202
- /// Like [`strings()`][File::strings()], but suitable for statically known `key`s like `remote.origin.url`.
203
- pub fn strings_by_key < ' a > ( & self , key : impl Into < & ' a BStr > ) -> Option < Vec < Cow < ' _ , BStr > > > {
204
- let key = crate :: parse:: key ( key. into ( ) ) ?;
205
- self . strings ( key. section_name , key. subsection_name , key. value_name )
198
+ /// Like [`strings()`][File::strings_by()], but suitable for statically known `key`s like `remote.origin.url`.
199
+ pub fn strings ( & self , key : impl Key ) -> Option < Vec < Cow < ' _ , BStr > > > {
200
+ self . strings_by ( key. section_name ( ) , key. subsection_name ( ) , key. name ( ) )
206
201
}
207
202
208
- /// Similar to [`strings(…)`][File::strings ()], but all values are in sections that passed `filter`.
209
- pub fn strings_filter (
203
+ /// Similar to [`strings(…)`][File::strings_by ()], but all values are in sections that passed `filter`.
204
+ pub fn strings_filter_by (
210
205
& self ,
211
206
section_name : impl AsRef < str > ,
212
207
subsection_name : Option < & BStr > ,
@@ -217,35 +212,34 @@ impl<'event> File<'event> {
217
212
. ok ( )
218
213
}
219
214
220
- /// Like [`strings_filter()`][File::strings_filter ()], but suitable for statically known `key`s like `remote.origin.url`.
221
- pub fn strings_filter_by_key < ' a > (
215
+ /// Like [`strings_filter()`][File::strings_filter_by ()], but suitable for statically known `key`s like `remote.origin.url`.
216
+ pub fn strings_filter (
222
217
& self ,
223
- key : impl Into < & ' a BStr > ,
218
+ key : impl Key ,
224
219
filter : & mut MetadataFilter ,
225
220
) -> Option < Vec < Cow < ' _ , BStr > > > {
226
- let key = crate :: parse:: key ( key. into ( ) ) ?;
227
- self . strings_filter ( key. section_name , key. subsection_name , key. value_name , filter)
221
+ self . strings_filter_by ( key. section_name ( ) , key. subsection_name ( ) , key. name ( ) , filter)
228
222
}
229
223
230
224
/// Similar to [`values(…)`][File::values()] but returning integers if at least one of them was found
231
225
/// and if none of them overflows.
232
- pub fn integers (
226
+ pub fn integers_by (
233
227
& self ,
234
228
section_name : impl AsRef < str > ,
235
229
subsection_name : Option < & BStr > ,
236
230
key : impl AsRef < str > ,
237
231
) -> Option < Result < Vec < i64 > , value:: Error > > {
238
- self . integers_filter ( section_name, subsection_name, key, & mut |_| true )
232
+ self . integers_filter_by ( section_name, subsection_name, key, & mut |_| true )
239
233
}
240
234
241
- /// Like [`integers()`][File::integers ()], but suitable for statically known `key`s like `remote.origin.url`.
242
- pub fn integers_by_key < ' a > ( & self , key : impl Into < & ' a BStr > ) -> Option < Result < Vec < i64 > , value:: Error > > {
243
- self . integers_filter_by_key ( key, & mut |_| true )
235
+ /// Like [`integers()`][File::integers_by ()], but suitable for statically known `key`s like `remote.origin.url`.
236
+ pub fn integers ( & self , key : impl Key ) -> Option < Result < Vec < i64 > , value:: Error > > {
237
+ self . integers_filter ( key, & mut |_| true )
244
238
}
245
239
246
- /// Similar to [`integers(…)`][File::integers ()] but all integers are in sections that passed `filter`
240
+ /// Similar to [`integers(…)`][File::integers_by ()] but all integers are in sections that passed `filter`
247
241
/// and that are not overflowing.
248
- pub fn integers_filter (
242
+ pub fn integers_filter_by (
249
243
& self ,
250
244
section_name : impl AsRef < str > ,
251
245
subsection_name : Option < & BStr > ,
@@ -267,13 +261,12 @@ impl<'event> File<'event> {
267
261
} )
268
262
}
269
263
270
- /// Like [`integers_filter()`][File::integers_filter ()], but suitable for statically known `key`s like `remote.origin.url`.
271
- pub fn integers_filter_by_key < ' a > (
264
+ /// Like [`integers_filter()`][File::integers_filter_by ()], but suitable for statically known `key`s like `remote.origin.url`.
265
+ pub fn integers_filter (
272
266
& self ,
273
- key : impl Into < & ' a BStr > ,
267
+ key : impl Key ,
274
268
filter : & mut MetadataFilter ,
275
269
) -> Option < Result < Vec < i64 > , value:: Error > > {
276
- let key = crate :: parse:: key ( key. into ( ) ) ?;
277
- self . integers_filter ( key. section_name , key. subsection_name , key. value_name , filter)
270
+ self . integers_filter_by ( key. section_name ( ) , key. subsection_name ( ) , key. name ( ) , filter)
278
271
}
279
272
}
0 commit comments