Skip to content

Commit 83a6da7

Browse files
committed
revert best-effort naming scheme in preference of all-or-nothing
1 parent a5ee896 commit 83a6da7

File tree

3 files changed

+3788
-3734
lines changed

3 files changed

+3788
-3734
lines changed

typify-impl/src/enums.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,7 @@ impl TypeSpace {
618618
.reduce(|a, b| get_common_prefix(&a, &b))
619619
.unwrap_or_else(String::new);
620620

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.
624622
let duplicate_names = variant_names
625623
.iter()
626624
.cloned()
@@ -636,25 +634,29 @@ impl TypeSpace {
636634
// Prune the common prefixes from all variant names. If this
637635
// results in any of them being empty, we don't use these names.
638636
//
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
640638
// the schema.
641639
let variant_names = variant_names
642-
.into_iter()
643-
.enumerate()
644-
.map(|(idx, var_name)| {
640+
.iter()
641+
.map(|var_name| {
645642
match var_name {
646643
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())),
650647
}
651648
.map(|var_name| var_name[common_prefix.len()..].to_string())
652649
.filter(|var_name| !var_name.is_empty())
653650
.map(|var_name| var_name.to_string())
654-
// Fall back to `VariantN` naming.
655-
.unwrap_or_else(|| format!("Variant{}", idx))
656651
})
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+
});
658660

659661
// Gather the variant details along with its name.
660662
let variant_details = subschemas

0 commit comments

Comments
 (0)