diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-31 15:06:36 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-31 15:06:36 +0100 |
| commit | 904d7f9db65fa5542cdd44b8dd360c271a931cc6 (patch) | |
| tree | a34aacccbf60af14f092d212d875d51560e2734d /src/main/java/org | |
| parent | 0a2349963e03a98c1fc3682cdd3cd70c3290011d (diff) | |
Handle boxed variants in rust-transient-0
Diffstat (limited to 'src/main/java/org')
2 files changed, 12 insertions, 3 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java index 2af97a8..ea1949d 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java @@ -483,9 +483,17 @@ public class RustTransient0Generator implements Generator { var variantPath = this.rustGenerator.generateRustTypeExpression(sumDefinition.type()) .addSegment(RustPathSegment.of(this.rustGenerator.generateVariantName(variantType))); + var valueExpression = generateDecode(variantType); + if (variant.isBox()) { + valueExpression = new RustCallExpression( + RustTypes.BOX.addSegment(RustPathSegment.of("new")), + List.of(valueExpression) + ); + } + return new RustMatchArm( new RustLiteralPattern(new RustIntegerLiteral(variantIndex, Optional.empty())), - new RustCallExpression(variantPath, List.of(generateDecode(variantType))) + new RustCallExpression(variantPath, List.of(valueExpression)) ); }) .collect(toArrayList()); diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustTypes.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustTypes.java index ec473b1..5e6303a 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustTypes.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustTypes.java @@ -22,9 +22,10 @@ public class RustTypes { public static RustPath ANY = RustPath.global("std", "any", "Any"); + public static final RustPath BOX = RustPath.global("std", "boxed", "Box"); + public static RustPath box(RustType elementType) { - return RustPath.global("std", "boxed", "Box") - .withArgs(List.of(elementType)); + return BOX.withArgs(List.of(elementType)); } public static RustPath hashMap(RustType keyType, RustType valueType) { |
