@@ -18,6 +18,11 @@ impl<'event> File<'event> {
18
18
self . string_filter ( 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 )
24
+ }
25
+
21
26
/// Like [`string()`][File::string()], but the section containing the returned value must pass `filter` as well.
22
27
pub fn string_filter (
23
28
& self ,
@@ -29,6 +34,17 @@ impl<'event> File<'event> {
29
34
self . raw_value_filter ( section_name, subsection_name, key, filter) . ok ( )
30
35
}
31
36
37
+ /// Like [`string_filter()`][File::string_filter()], but suitable for statically known `key`s like `remote.origin.url`.
38
+ pub fn string_filter_by_key < ' a > (
39
+ & self ,
40
+ key : impl Into < & ' a BStr > ,
41
+ filter : & mut MetadataFilter ,
42
+ ) -> Option < Cow < ' _ , BStr > > {
43
+ let key = crate :: parse:: key ( key) ?;
44
+ self . raw_value_filter ( key. section_name , key. subsection_name , key. value_name , filter)
45
+ . ok ( )
46
+ }
47
+
32
48
/// Like [`value()`][File::value()], but returning `None` if the path wasn't found.
33
49
///
34
50
/// Note that this path is not vetted and should only point to resources which can't be used
@@ -44,6 +60,11 @@ impl<'event> File<'event> {
44
60
self . path_filter ( section_name, subsection_name, key, & mut |_| true )
45
61
}
46
62
63
+ /// Like [`path()`][File::path()], but suitable for statically known `key`s like `remote.origin.url`.
64
+ pub fn path_by_key < ' a > ( & self , key : impl Into < & ' a BStr > ) -> Option < crate :: Path < ' _ > > {
65
+ self . path_filter_by_key ( key, & mut |_| true )
66
+ }
67
+
47
68
/// Like [`path()`][File::path()], but the section containing the returned value must pass `filter` as well.
48
69
///
49
70
/// This should be the preferred way of accessing paths as those from untrusted
@@ -62,6 +83,16 @@ impl<'event> File<'event> {
62
83
. map ( crate :: Path :: from)
63
84
}
64
85
86
+ /// Like [`path_filter()`][File::path_filter()], but suitable for statically known `key`s like `remote.origin.url`.
87
+ pub fn path_filter_by_key < ' a > (
88
+ & self ,
89
+ key : impl Into < & ' a BStr > ,
90
+ filter : & mut MetadataFilter ,
91
+ ) -> Option < crate :: Path < ' _ > > {
92
+ let key = crate :: parse:: key ( key) ?;
93
+ self . path_filter ( key. section_name , key. subsection_name , key. value_name , filter)
94
+ }
95
+
65
96
/// Like [`value()`][File::value()], but returning `None` if the boolean value wasn't found.
66
97
pub fn boolean (
67
98
& self ,
@@ -72,6 +103,11 @@ impl<'event> File<'event> {
72
103
self . boolean_filter ( section_name, subsection_name, key, & mut |_| true )
73
104
}
74
105
106
+ /// Like [`boolean()`][File::boolean()], but suitable for statically known `key`s like `remote.origin.url`.
107
+ pub fn boolean_by_key < ' a > ( & self , key : impl Into < & ' a BStr > ) -> Option < Result < bool , value:: Error > > {
108
+ self . boolean_filter_by_key ( key, & mut |_| true )
109
+ }
110
+
75
111
/// Like [`boolean()`][File::boolean()], but the section containing the returned value must pass `filter` as well.
76
112
pub fn boolean_filter (
77
113
& self ,
@@ -99,6 +135,16 @@ impl<'event> File<'event> {
99
135
None
100
136
}
101
137
138
+ /// Like [`boolean_filter()`][File::boolean_filter()], but suitable for statically known `key`s like `remote.origin.url`.
139
+ pub fn boolean_filter_by_key < ' a > (
140
+ & self ,
141
+ key : impl Into < & ' a BStr > ,
142
+ filter : & mut MetadataFilter ,
143
+ ) -> Option < Result < bool , value:: Error > > {
144
+ let key = crate :: parse:: key ( key) ?;
145
+ self . boolean_filter ( key. section_name , key. subsection_name , key. value_name , filter)
146
+ }
147
+
102
148
/// Like [`value()`][File::value()], but returning an `Option` if the integer wasn't found.
103
149
pub fn integer (
104
150
& self ,
@@ -109,6 +155,11 @@ impl<'event> File<'event> {
109
155
self . integer_filter ( section_name, subsection_name, key, & mut |_| true )
110
156
}
111
157
158
+ /// Like [`integer()`][File::integer()], but suitable for statically known `key`s like `remote.origin.url`.
159
+ pub fn integer_by_key < ' a > ( & self , key : impl Into < & ' a BStr > ) -> Option < Result < i64 , value:: Error > > {
160
+ self . integer_filter_by_key ( key, & mut |_| true )
161
+ }
162
+
112
163
/// Like [`integer()`][File::integer()], but the section containing the returned value must pass `filter` as well.
113
164
pub fn integer_filter (
114
165
& self ,
@@ -124,6 +175,16 @@ impl<'event> File<'event> {
124
175
} ) )
125
176
}
126
177
178
+ /// Like [`integer_filter()`][File::integer_filter()], but suitable for statically known `key`s like `remote.origin.url`.
179
+ pub fn integer_filter_by_key < ' a > (
180
+ & self ,
181
+ key : impl Into < & ' a BStr > ,
182
+ filter : & mut MetadataFilter ,
183
+ ) -> Option < Result < i64 , value:: Error > > {
184
+ let key = crate :: parse:: key ( key) ?;
185
+ self . integer_filter ( key. section_name , key. subsection_name , key. value_name , filter)
186
+ }
187
+
127
188
/// Similar to [`values(…)`][File::values()] but returning strings if at least one of them was found.
128
189
pub fn strings (
129
190
& self ,
@@ -134,6 +195,12 @@ impl<'event> File<'event> {
134
195
self . raw_values ( section_name, subsection_name, key) . ok ( )
135
196
}
136
197
198
+ /// Like [`strings()`][File::strings()], but suitable for statically known `key`s like `remote.origin.url`.
199
+ pub fn strings_by_key < ' a > ( & self , key : impl Into < & ' a BStr > ) -> Option < Vec < Cow < ' _ , BStr > > > {
200
+ let key = crate :: parse:: key ( key) ?;
201
+ self . strings ( key. section_name , key. subsection_name , key. value_name )
202
+ }
203
+
137
204
/// Similar to [`strings(…)`][File::strings()], but all values are in sections that passed `filter`.
138
205
pub fn strings_filter (
139
206
& self ,
@@ -145,6 +212,16 @@ impl<'event> File<'event> {
145
212
self . raw_values_filter ( section_name, subsection_name, key, filter) . ok ( )
146
213
}
147
214
215
+ /// Like [`strings_filter()`][File::strings_filter()], but suitable for statically known `key`s like `remote.origin.url`.
216
+ pub fn strings_filter_by_key < ' a > (
217
+ & self ,
218
+ key : impl Into < & ' a BStr > ,
219
+ filter : & mut MetadataFilter ,
220
+ ) -> Option < Vec < Cow < ' _ , BStr > > > {
221
+ let key = crate :: parse:: key ( key) ?;
222
+ self . strings_filter ( key. section_name , key. subsection_name , key. value_name , filter)
223
+ }
224
+
148
225
/// Similar to [`values(…)`][File::values()] but returning integers if at least one of them was found
149
226
/// and if none of them overflows.
150
227
pub fn integers (
@@ -156,6 +233,11 @@ impl<'event> File<'event> {
156
233
self . integers_filter ( section_name, subsection_name, key, & mut |_| true )
157
234
}
158
235
236
+ /// Like [`integers()`][File::integers()], but suitable for statically known `key`s like `remote.origin.url`.
237
+ pub fn integers_by_key < ' a > ( & self , key : impl Into < & ' a BStr > ) -> Option < Result < Vec < i64 > , value:: Error > > {
238
+ self . integers_filter_by_key ( key, & mut |_| true )
239
+ }
240
+
159
241
/// Similar to [`integers(…)`][File::integers()] but all integers are in sections that passed `filter`
160
242
/// and that are not overflowing.
161
243
pub fn integers_filter (
@@ -179,4 +261,14 @@ impl<'event> File<'event> {
179
261
. collect ( )
180
262
} )
181
263
}
264
+
265
+ /// Like [`integers_filter()`][File::integers_filter()], but suitable for statically known `key`s like `remote.origin.url`.
266
+ pub fn integers_filter_by_key < ' a > (
267
+ & self ,
268
+ key : impl Into < & ' a BStr > ,
269
+ filter : & mut MetadataFilter ,
270
+ ) -> Option < Result < Vec < i64 > , value:: Error > > {
271
+ let key = crate :: parse:: key ( key) ?;
272
+ self . integers_filter ( key. section_name , key. subsection_name , key. value_name , filter)
273
+ }
182
274
}
0 commit comments