summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java10
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustTypes.java5
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) {