@@ -10,7 +10,7 @@ use super::datetime::{
10
10
use super :: parse_json:: JsonArray ;
11
11
use super :: shared:: { float_as_int, int_as_bool, map_json_err, str_as_bool, str_as_int} ;
12
12
use super :: {
13
- EitherBytes , EitherString , EitherTimedelta , GenericArguments , GenericCollection , GenericIterator , GenericMapping ,
13
+ EitherBytes , EitherString , EitherTimedelta , GenericArguments , GenericIterable , GenericIterator , GenericMapping ,
14
14
Input , JsonArgs , JsonInput ,
15
15
} ;
16
16
@@ -187,53 +187,62 @@ impl<'a> Input<'a> for JsonInput {
187
187
self . validate_dict ( false )
188
188
}
189
189
190
- fn validate_list ( & ' a self , _strict : bool , _allow_any_iter : bool ) -> ValResult < GenericCollection < ' a > > {
190
+ fn validate_list ( & ' a self , _strict : bool ) -> ValResult < GenericIterable < ' a > > {
191
191
match self {
192
- JsonInput :: Array ( a) => Ok ( a . into ( ) ) ,
192
+ JsonInput :: Array ( a) => Ok ( GenericIterable :: JsonArray ( a ) ) ,
193
193
_ => Err ( ValError :: new ( ErrorType :: ListType , self ) ) ,
194
194
}
195
195
}
196
196
#[ cfg_attr( has_no_coverage, no_coverage) ]
197
- fn strict_list ( & ' a self ) -> ValResult < GenericCollection < ' a > > {
198
- self . validate_list ( false , false )
197
+ fn strict_list ( & ' a self ) -> ValResult < GenericIterable < ' a > > {
198
+ self . validate_list ( false )
199
199
}
200
200
201
- fn validate_tuple ( & ' a self , _strict : bool ) -> ValResult < GenericCollection < ' a > > {
201
+ fn validate_tuple ( & ' a self , _strict : bool ) -> ValResult < GenericIterable < ' a > > {
202
202
// just as in set's case, List has to be allowed
203
203
match self {
204
- JsonInput :: Array ( a) => Ok ( a . into ( ) ) ,
204
+ JsonInput :: Array ( a) => Ok ( GenericIterable :: JsonArray ( a ) ) ,
205
205
_ => Err ( ValError :: new ( ErrorType :: TupleType , self ) ) ,
206
206
}
207
207
}
208
208
#[ cfg_attr( has_no_coverage, no_coverage) ]
209
- fn strict_tuple ( & ' a self ) -> ValResult < GenericCollection < ' a > > {
209
+ fn strict_tuple ( & ' a self ) -> ValResult < GenericIterable < ' a > > {
210
210
self . validate_tuple ( false )
211
211
}
212
212
213
- fn validate_set ( & ' a self , _strict : bool ) -> ValResult < GenericCollection < ' a > > {
213
+ fn validate_set ( & ' a self , _strict : bool ) -> ValResult < GenericIterable < ' a > > {
214
214
// we allow a list here since otherwise it would be impossible to create a set from JSON
215
215
match self {
216
- JsonInput :: Array ( a) => Ok ( a . into ( ) ) ,
216
+ JsonInput :: Array ( a) => Ok ( GenericIterable :: JsonArray ( a ) ) ,
217
217
_ => Err ( ValError :: new ( ErrorType :: SetType , self ) ) ,
218
218
}
219
219
}
220
220
#[ cfg_attr( has_no_coverage, no_coverage) ]
221
- fn strict_set ( & ' a self ) -> ValResult < GenericCollection < ' a > > {
221
+ fn strict_set ( & ' a self ) -> ValResult < GenericIterable < ' a > > {
222
222
self . validate_set ( false )
223
223
}
224
224
225
- fn validate_frozenset ( & ' a self , _strict : bool ) -> ValResult < GenericCollection < ' a > > {
225
+ fn validate_frozenset ( & ' a self , _strict : bool ) -> ValResult < GenericIterable < ' a > > {
226
226
// we allow a list here since otherwise it would be impossible to create a frozenset from JSON
227
227
match self {
228
- JsonInput :: Array ( a) => Ok ( a . into ( ) ) ,
228
+ JsonInput :: Array ( a) => Ok ( GenericIterable :: JsonArray ( a ) ) ,
229
229
_ => Err ( ValError :: new ( ErrorType :: FrozenSetType , self ) ) ,
230
230
}
231
231
}
232
232
#[ cfg_attr( has_no_coverage, no_coverage) ]
233
- fn strict_frozenset ( & ' a self ) -> ValResult < GenericCollection < ' a > > {
233
+ fn strict_frozenset ( & ' a self ) -> ValResult < GenericIterable < ' a > > {
234
234
self . validate_frozenset ( false )
235
235
}
236
236
237
+ fn extract_generic_iterable ( & self ) -> ValResult < GenericIterable > {
238
+ match self {
239
+ JsonInput :: Array ( a) => Ok ( GenericIterable :: JsonArray ( a) ) ,
240
+ JsonInput :: String ( s) => Ok ( GenericIterable :: JsonString ( s) ) ,
241
+ JsonInput :: Object ( object) => Ok ( GenericIterable :: JsonObject ( object) ) ,
242
+ _ => Err ( ValError :: new ( ErrorType :: IterableType , self ) ) ,
243
+ }
244
+ }
245
+
237
246
fn validate_iter ( & self ) -> ValResult < GenericIterator > {
238
247
match self {
239
248
JsonInput :: Array ( a) => Ok ( a. clone ( ) . into ( ) ) ,
@@ -405,41 +414,45 @@ impl<'a> Input<'a> for String {
405
414
}
406
415
407
416
#[ cfg_attr( has_no_coverage, no_coverage) ]
408
- fn validate_list ( & ' a self , _strict : bool , _allow_any_iter : bool ) -> ValResult < GenericCollection < ' a > > {
417
+ fn validate_list ( & ' a self , _strict : bool ) -> ValResult < GenericIterable < ' a > > {
409
418
Err ( ValError :: new ( ErrorType :: ListType , self ) )
410
419
}
411
420
#[ cfg_attr( has_no_coverage, no_coverage) ]
412
- fn strict_list ( & ' a self ) -> ValResult < GenericCollection < ' a > > {
413
- self . validate_list ( false , false )
421
+ fn strict_list ( & ' a self ) -> ValResult < GenericIterable < ' a > > {
422
+ self . validate_list ( false )
414
423
}
415
424
416
425
#[ cfg_attr( has_no_coverage, no_coverage) ]
417
- fn validate_tuple ( & ' a self , _strict : bool ) -> ValResult < GenericCollection < ' a > > {
426
+ fn validate_tuple ( & ' a self , _strict : bool ) -> ValResult < GenericIterable < ' a > > {
418
427
Err ( ValError :: new ( ErrorType :: TupleType , self ) )
419
428
}
420
429
#[ cfg_attr( has_no_coverage, no_coverage) ]
421
- fn strict_tuple ( & ' a self ) -> ValResult < GenericCollection < ' a > > {
430
+ fn strict_tuple ( & ' a self ) -> ValResult < GenericIterable < ' a > > {
422
431
self . validate_tuple ( false )
423
432
}
424
433
425
434
#[ cfg_attr( has_no_coverage, no_coverage) ]
426
- fn validate_set ( & ' a self , _strict : bool ) -> ValResult < GenericCollection < ' a > > {
435
+ fn validate_set ( & ' a self , _strict : bool ) -> ValResult < GenericIterable < ' a > > {
427
436
Err ( ValError :: new ( ErrorType :: SetType , self ) )
428
437
}
429
438
#[ cfg_attr( has_no_coverage, no_coverage) ]
430
- fn strict_set ( & ' a self ) -> ValResult < GenericCollection < ' a > > {
439
+ fn strict_set ( & ' a self ) -> ValResult < GenericIterable < ' a > > {
431
440
self . validate_set ( false )
432
441
}
433
442
434
443
#[ cfg_attr( has_no_coverage, no_coverage) ]
435
- fn validate_frozenset ( & ' a self , _strict : bool ) -> ValResult < GenericCollection < ' a > > {
444
+ fn validate_frozenset ( & ' a self , _strict : bool ) -> ValResult < GenericIterable < ' a > > {
436
445
Err ( ValError :: new ( ErrorType :: FrozenSetType , self ) )
437
446
}
438
447
#[ cfg_attr( has_no_coverage, no_coverage) ]
439
- fn strict_frozenset ( & ' a self ) -> ValResult < GenericCollection < ' a > > {
448
+ fn strict_frozenset ( & ' a self ) -> ValResult < GenericIterable < ' a > > {
440
449
self . validate_frozenset ( false )
441
450
}
442
451
452
+ fn extract_generic_iterable ( & ' a self ) -> ValResult < GenericIterable < ' a > > {
453
+ Ok ( GenericIterable :: JsonString ( self ) )
454
+ }
455
+
443
456
fn validate_iter ( & self ) -> ValResult < GenericIterator > {
444
457
Ok ( string_to_vec ( self ) . into ( ) )
445
458
}
0 commit comments