( enumName: string, value: string, ctx: RustCodegenCtx, description?: string, )
| 1016 | } |
| 1017 | |
| 1018 | function emitRustConstStringEnum( |
| 1019 | enumName: string, |
| 1020 | value: string, |
| 1021 | ctx: RustCodegenCtx, |
| 1022 | description?: string, |
| 1023 | ): void { |
| 1024 | if (ctx.generatedNames.has(enumName)) return; |
| 1025 | ctx.generatedNames.add(enumName); |
| 1026 | |
| 1027 | const lines: string[] = []; |
| 1028 | if (description) { |
| 1029 | for (const line of description.split(/\r?\n/)) { |
| 1030 | lines.push(`/// ${line}`); |
| 1031 | } |
| 1032 | } |
| 1033 | lines.push( |
| 1034 | "#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]", |
| 1035 | ); |
| 1036 | lines.push(`pub enum ${enumName} {`); |
| 1037 | const variantName = toRustPascalIdentifier(value, "Value"); |
| 1038 | if (variantName !== value) { |
| 1039 | lines.push(` #[serde(rename = "${value}")]`); |
| 1040 | } |
| 1041 | lines.push(" #[default]"); |
| 1042 | lines.push(` ${variantName},`); |
| 1043 | lines.push("}"); |
| 1044 | ctx.enums.push(lines.join("\n")); |
| 1045 | } |
| 1046 | |
| 1047 | // ── Session events generation ─────────────────────────────────────────────── |
| 1048 |
no test coverage detected
searching dependent graphs…