@@ -227,21 +227,25 @@ pub type InstantiatedFilterType =
227
227
pub enum SingleOrMany < A : Info < Supported = All > , M : Info < Supported = Language > > {
228
228
All ( A ) ,
229
229
Many ( Many < M > ) ,
230
+ Single ( M ) ,
230
231
}
231
232
impl < A : Info < Supported = All > , M : Info < Supported = Language > > SingleOrMany < A , M > {
232
233
#[ must_use]
233
234
pub fn filter_name ( & self ) -> String {
234
235
match self {
235
236
Self :: All ( f) => f. filter_name ( ) ,
236
237
Self :: Many ( many) => many. name . clone ( ) ,
238
+ Self :: Single ( s) => s. filter_name ( ) ,
237
239
}
238
240
}
239
241
240
242
#[ must_use]
241
243
pub fn supports ( & self ) -> SupportedLanguages {
242
244
match self {
245
+ // Self::Single(s) => SupportedLanguages::Single(s.)
243
246
Self :: All ( _) => SupportedLanguages :: All ,
244
247
Self :: Many ( many) => SupportedLanguages :: Many ( many. filters . keys ( ) . cloned ( ) . collect ( ) ) ,
248
+ SingleOrMany :: Single ( _) => todo ! ( ) ,
245
249
}
246
250
}
247
251
}
@@ -251,9 +255,17 @@ impl<A: Info<Supported = All>, M: Info<Supported = Language>> Display for Single
251
255
}
252
256
}
253
257
impl < ' a > FilterType < ' a > {
258
+ pub fn specific ( & self , s : & str ) -> Option < Self > {
259
+ match self {
260
+ Self :: All ( _) | Self :: Single ( _) => None ,
261
+ Self :: Many ( m) => m. filters . get ( s) . map ( |x| Self :: Single ( * x) ) ,
262
+ }
263
+ }
264
+
254
265
pub fn to_filter ( & self , s : & str ) -> Result < InstantiatedFilterType , String > {
255
266
match self {
256
267
SingleOrMany :: All ( a) => a. to_filter ( s) . map ( SingleOrMany :: All ) ,
268
+ SingleOrMany :: Single ( a) => a. to_filter ( s) . map ( SingleOrMany :: Single ) ,
257
269
SingleOrMany :: Many ( Many { name, filters } ) => filters
258
270
. iter ( )
259
271
. map ( |( name, f) | f. to_filter ( s) . map ( |f| ( name. clone ( ) , f) ) )
@@ -345,6 +357,13 @@ impl<'a> Filters<'a> {
345
357
match filters {
346
358
SingleOrMany :: All ( _) => Err ( "cannot add to an all filter" . to_string ( ) ) ,
347
359
SingleOrMany :: Many ( Many { filters, .. } ) => merge_filters ( filters, filter) ,
360
+ SingleOrMany :: Single ( s) => {
361
+ * filters = SingleOrMany :: Many ( Many {
362
+ name : "" . to_string ( ) ,
363
+ filters : HashMap :: from ( [ ( s. filter_name ( ) , * s) ] ) ,
364
+ } ) ;
365
+ Ok ( ( ) )
366
+ }
348
367
}
349
368
} else {
350
369
self . filters . insert ( name, filter) ;
0 commit comments