summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-07-26 12:06:42 +0100
committerMichael Williamson <mike@zwobble.org>2026-07-26 12:06:42 +0100
commita9f618b86908aaff180573907f9096537aa839eb (patch)
tree5126a65e8ac73745da62118c986bf63efaabb7a5
parentaa83cfed61ea4d68377261ce2a44fea9af24a692 (diff)
Reuse values from RustTypes
-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, 8 insertions, 7 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 3c8000c..b34206e 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
@@ -700,7 +700,7 @@ public class RustTransient0Generator implements Generator {
List.of(
new RustLetStatement(length, false, generateDecode(NativeTypes.INT_64)),
new RustLetStatement(elements, true, new RustCallExpression(
- RustPath.global("std", "vec", "Vec", "with_capacity"),
+ RustTypes.VEC.addSegment(RustPathSegment.of("with_capacity")),
List.of(tryIntoOrInvalidData(RustPath.of(length)))
)),
new RustExpressionStatement(new RustIteratorLoopExpression(
@@ -728,7 +728,7 @@ public class RustTransient0Generator implements Generator {
List.of(
new RustMatchArm(
new RustTupleStructPattern(
- RustPath.global("std", "option", "Option", "Some"),
+ RustTypes.SOME,
List.of(new RustIdentifierPattern(VALUE_NAME))
),
new RustBlockExpression(
@@ -749,7 +749,7 @@ public class RustTransient0Generator implements Generator {
)
),
new RustMatchArm(
- new RustPathPattern(RustPath.global("std", "option", "Option", "None")),
+ new RustPathPattern(RustTypes.NONE),
new RustBlockExpression(
List.of(
generateEncode(
@@ -777,7 +777,7 @@ public class RustTransient0Generator implements Generator {
List.of(),
Optional.of(
new RustCallExpression(
- RustPath.global("std", "option", "Option", "Some"),
+ RustTypes.SOME,
List.of(generateDecode(elementType))
)
)
@@ -785,7 +785,7 @@ public class RustTransient0Generator implements Generator {
new RustBlockExpression(
List.of(),
Optional.of(
- RustPath.global("std", "option", "Option", "None")
+ RustTypes.NONE
)
)
))
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 c0ee970..1dea2b0 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
@@ -52,8 +52,9 @@ public class RustTypes {
return ARC.withArgs(List.of(innerType));
}
+ public static RustPath VEC = RustPath.global("std", "vec", "Vec");
+
public static RustPath vec(RustType elementType) {
- return RustPath.global("std", "vec", "Vec")
- .withArgs(List.of(elementType));
+ return VEC.withArgs(List.of(elementType));
}
}