@@ -330,75 +330,89 @@ impl From<BuildSpecVisitor> for UncheckedBuildSpec {
330
330
impl < ' de > Deserialize < ' de > for UncheckedBuildSpec {
331
331
fn deserialize < D > ( deserializer : D ) -> std:: result:: Result < Self , D :: Error >
332
332
where
333
- D : serde:: Deserializer < ' de > ,
333
+ D : serde:: de :: Deserializer < ' de > ,
334
334
{
335
- struct UncheckedBuildSpecVisitor ;
335
+ Ok ( deserializer
336
+ . deserialize_map ( BuildSpecVisitor :: default ( ) ) ?
337
+ . into ( ) )
338
+ }
339
+ }
336
340
337
- impl < ' de > serde:: de:: Visitor < ' de > for UncheckedBuildSpecVisitor {
338
- type Value = UncheckedBuildSpec ;
341
+ impl < ' de > Deserialize < ' de > for LintedItem < UncheckedBuildSpec > {
342
+ fn deserialize < D > ( deserializer : D ) -> std:: result:: Result < Self , D :: Error >
343
+ where
344
+ D : serde:: de:: Deserializer < ' de > ,
345
+ {
346
+ Ok ( deserializer
347
+ . deserialize_map ( BuildSpecVisitor :: default ( ) ) ?
348
+ . into ( ) )
349
+ }
350
+ }
339
351
340
- fn expecting ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
341
- f. write_str ( "a build specification" )
342
- }
352
+ impl < ' de > serde:: de:: Visitor < ' de > for BuildSpecVisitor {
353
+ type Value = BuildSpecVisitor ;
343
354
344
- fn visit_map < A > ( self , mut map : A ) -> std:: result:: Result < Self :: Value , A :: Error >
345
- where
346
- A : serde:: de:: MapAccess < ' de > ,
347
- {
348
- let mut variants = Vec :: < v0:: VariantSpec > :: new ( ) ;
349
- let mut unchecked = BuildSpec :: default ( ) ;
350
- while let Some ( key) = map. next_key :: < Stringified > ( ) ? {
351
- match key. as_str ( ) {
352
- "script" => unchecked. script = map. next_value :: < Script > ( ) ?,
353
- "options" => {
354
- unchecked. options = map. next_value :: < Vec < Opt > > ( ) ?;
355
- let mut unique_options = HashSet :: new ( ) ;
356
- for opt in unchecked. options . iter ( ) {
357
- let full_name = opt. full_name ( ) ;
358
- if unique_options. contains ( full_name) {
359
- return Err ( serde:: de:: Error :: custom ( format ! (
360
- "build option was specified more than once: {full_name}" ,
361
- ) ) ) ;
362
- }
363
- unique_options. insert ( full_name) ;
364
- }
365
- }
366
- "variants" => {
367
- variants = map. next_value ( ) ?;
368
- }
369
- "validation" => {
370
- unchecked. validation = map. next_value :: < ValidationSpec > ( ) ?
371
- }
372
- "auto_host_vars" => {
373
- unchecked. auto_host_vars = map. next_value :: < AutoHostVars > ( ) ?
374
- }
375
- unknown_key => {
376
- let lint =
377
- UnknownKey :: new ( unknown_key, BuildSpec :: FIELD_NAMES_AS_ARRAY . to_vec ( ) ) ;
378
- self . lints . push ( lint. message . to_string ( ) ) ;
379
- map. next_value :: < serde:: de:: IgnoredAny > ( ) ?;
355
+ fn expecting ( & self , f : & mut std:: fmt:: Formatter ) -> std:: fmt:: Result {
356
+ f. write_str ( "a build specification" )
357
+ }
358
+
359
+ fn visit_map < A > ( mut self , mut map : A ) -> std:: result:: Result < Self :: Value , A :: Error >
360
+ where
361
+ A : serde:: de:: MapAccess < ' de > ,
362
+ {
363
+ let mut variants = Vec :: < v0:: VariantSpec > :: new ( ) ;
364
+ let mut unchecked = BuildSpec :: default ( ) ;
365
+ while let Some ( key) = map. next_key :: < Stringified > ( ) ? {
366
+ match key. as_str ( ) {
367
+ "script" => unchecked. script = map. next_value :: < Script > ( ) ?,
368
+ "options" => {
369
+ unchecked. options = map. next_value :: < Vec < Opt > > ( ) ?;
370
+ let mut unique_options = HashSet :: new ( ) ;
371
+ for opt in unchecked. options . iter ( ) {
372
+ let full_name = opt. full_name ( ) ;
373
+ if unique_options. contains ( full_name) {
374
+ return Err ( serde:: de:: Error :: custom ( format ! (
375
+ "build option was specified more than once: {full_name}" ,
376
+ ) ) ) ;
380
377
}
381
-
378
+ unique_options . insert ( full_name ) ;
382
379
}
383
380
}
384
-
385
- if variants. is_empty ( ) {
386
- variants. push ( Default :: default ( ) ) ;
381
+ "variants" => {
382
+ variants = map. next_value ( ) ?;
383
+ }
384
+ "validation" => {
385
+ unchecked. validation = map. next_value :: < ValidationSpec > ( ) ?
386
+ }
387
+ "auto_host_vars" => {
388
+ unchecked. auto_host_vars = map. next_value :: < AutoHostVars > ( ) ?
389
+ }
390
+ unknown_key => {
391
+ self . lints . push ( Lint :: Key ( UnknownKey :: new (
392
+ unknown_key,
393
+ BuildSpec :: FIELD_NAMES_AS_ARRAY . to_vec ( ) ,
394
+ ) ) ) ;
395
+ map. next_value :: < serde:: de:: IgnoredAny > ( ) ?;
387
396
}
388
-
389
- // we can only parse out the final variant forms after all the
390
- // build options have been loaded
391
- unchecked. variants = variants
392
- . into_iter ( )
393
- . map ( |o| v0:: Variant :: from_spec ( o, & unchecked. options ) )
394
- . collect :: < Result < Vec < _ > > > ( )
395
- . map_err ( serde:: de:: Error :: custom) ?;
396
-
397
- Ok ( UncheckedBuildSpec ( unchecked) )
398
397
}
399
398
}
400
399
401
- deserializer. deserialize_map ( UncheckedBuildSpecVisitor )
400
+ if variants. is_empty ( ) {
401
+ variants. push ( Default :: default ( ) ) ;
402
+ }
403
+
404
+ // we can only parse out the final variant forms after all the
405
+ // build options have been loaded
406
+ unchecked. variants = variants
407
+ . into_iter ( )
408
+ . map ( |o| v0:: Variant :: from_spec ( o, & unchecked. options ) )
409
+ . collect :: < Result < Vec < _ > > > ( )
410
+ . map_err ( serde:: de:: Error :: custom) ?;
411
+
412
+ Ok ( Self {
413
+ build_spec : UncheckedBuildSpec ( unchecked) ,
414
+ lints : self . lints ,
415
+ } )
402
416
}
403
417
}
404
418
/// Some shell script to be executed
0 commit comments