Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion scripts/codegen/rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ const STRING_NEWTYPE_OVERRIDES: Record<string, string> = {
requestId: "RequestId",
};

const STRING_ENUM_VARIANT_OVERRIDES: Record<string, Record<string, string>> = {
CatalogTrustEligibility: {
unknown: "UnknownValue",
},
};

// ── Naming helpers ──────────────────────────────────────────────────────────

function toPascalCase(s: string): string {
Expand Down Expand Up @@ -115,8 +121,9 @@ function uniqueRustPascalIdentifier(
used: Set<string>,
fallback: string,
reserved: Set<string> = new Set(),
override?: string,
): string {
const identifier = toRustPascalIdentifier(value, fallback);
const identifier = override ?? toRustPascalIdentifier(value, fallback);
if (used.has(identifier) || reserved.has(identifier)) {
throw new Error(
`Generated Rust enum variant identifier "${identifier}" is not unique for value "${value}". Add an explicit naming rule instead of stabilizing an arbitrary public variant name.`,
Expand Down Expand Up @@ -1045,6 +1052,7 @@ function emitRustStringEnum(
usedVariantNames,
"Value",
reservedVariantNames,
STRING_ENUM_VARIANT_OVERRIDES[enumName]?.[value],
);
pushRustDoc(lines, enumValueDescriptions?.[value], " ");
if (variantName !== value) {
Expand Down
Loading