@@ -618,9 +618,7 @@ impl TypeSpace {
618
618
. reduce ( |a, b| get_common_prefix ( & a, & b) )
619
619
. unwrap_or_else ( String :: new) ;
620
620
621
- // Store seen, un-stripped names here. Any item for which their
622
- // name appears more than once, ALL the items with that clashing
623
- // name will be converted to the `VariantN` scheme.
621
+ // Store seen, un-stripped names here.
624
622
let duplicate_names = variant_names
625
623
. iter ( )
626
624
. cloned ( )
@@ -636,25 +634,29 @@ impl TypeSpace {
636
634
// Prune the common prefixes from all variant names. If this
637
635
// results in any of them being empty, we don't use these names.
638
636
//
639
- // Fall back to VariantN if the variant name cannot be derived from
637
+ // Fall back to VariantN if ALL variant names cannot be derived from
640
638
// the schema.
641
639
let variant_names = variant_names
642
- . into_iter ( )
643
- . enumerate ( )
644
- . map ( |( idx, var_name) | {
640
+ . iter ( )
641
+ . map ( |var_name| {
645
642
match var_name {
646
643
None => None ,
647
- var_name => {
648
- var_name . filter ( |var_name| !duplicate_names . contains ( var_name . as_str ( ) ) )
649
- }
644
+ var_name => var_name
645
+ . as_ref ( )
646
+ . filter ( |var_name| !duplicate_names . contains ( var_name . as_str ( ) ) ) ,
650
647
}
651
648
. map ( |var_name| var_name[ common_prefix. len ( ) ..] . to_string ( ) )
652
649
. filter ( |var_name| !var_name. is_empty ( ) )
653
650
. map ( |var_name| var_name. to_string ( ) )
654
- // Fall back to `VariantN` naming.
655
- . unwrap_or_else ( || format ! ( "Variant{}" , idx) )
656
651
} )
657
- . collect :: < Vec < _ > > ( ) ;
652
+ . collect :: < Option < Vec < _ > > > ( )
653
+ . unwrap_or_else ( || {
654
+ variant_names
655
+ . iter ( )
656
+ . enumerate ( )
657
+ . map ( |( idx, _) | format ! ( "Variant{idx}" ) )
658
+ . collect ( )
659
+ } ) ;
658
660
659
661
// Gather the variant details along with its name.
660
662
let variant_details = subschemas
0 commit comments