diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-26 12:04:37 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-26 12:04:37 +0100 |
| commit | aa83cfed61ea4d68377261ce2a44fea9af24a692 (patch) | |
| tree | 86475c8a4dd8652aa323ca8ee622a82d3ed44e31 /src/main/java | |
| parent | ebe855b47a5af50f9acc7a6b265904055e403bce (diff) | |
Extract IO result into RustTypes
Diffstat (limited to 'src/main/java')
2 files changed, 14 insertions, 8 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 734e7f7..3c8000c 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 @@ -518,14 +518,13 @@ public class RustTransient0Generator implements Generator { ) ), Optional.of( - RustPath.global("std", "io", "Result") - .withArgs(List.of(new RustTupleType(List.of()))) + RustTypes.ioResult(RustTypes.UNIT) ), Optional.of(new RustBlockExpression( body, Optional.of( new RustCallExpression( - RustPath.global("std", "io", "Result", "Ok"), + RustTypes.IO_RESULT_OK, List.of(new RustTupleExpression(List.of())) ) ) @@ -548,10 +547,10 @@ public class RustTransient0Generator implements Generator { RustTypes.vec(RustTypes.arc(RustTypes.dyn(RustTypes.ANY, RustTypes.SYNC, RustTypes.SEND))) )) ), - Optional.of(RustPath.global("std", "io", "Result").withArgs(List.of(rustType))), + Optional.of(RustTypes.ioResult(rustType)), Optional.of(new RustBlockExpression( body.statements(), - body.finalOperand().map(finalOperand -> new RustCallExpression(RustPath.of("std", "io", "Result", "Ok"), List.of(finalOperand))) + body.finalOperand().map(finalOperand -> new RustCallExpression(RustTypes.IO_RESULT_OK, List.of(finalOperand))) )) ); } 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 1e43a24..c0ee970 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 @@ -1,8 +1,6 @@ package org.zwobble.hobgoblin.compiler.output.lang.rust; -import org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustPath; -import org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTraitObjectType; -import org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustType; +import org.zwobble.hobgoblin.compiler.output.lang.rust.ast.*; import java.util.Arrays; import java.util.List; @@ -19,6 +17,8 @@ public class RustTypes { public static RustPath I64 = RustPath.primitive("i64"); public static RustPath USIZE = RustPath.primitive("usize"); + public static RustType UNIT = new RustTupleType(List.of()); + public static RustPath ANY = RustPath.global("std", "any", "Any"); public static RustPath box(RustType elementType) { @@ -31,6 +31,13 @@ public class RustTypes { .withArgs(List.of(keyType, valueType)); } + public static RustPath IO_RESULT = RustPath.global("std", "io", "Result"); + public static RustPath IO_RESULT_OK = IO_RESULT.addSegment(RustPathSegment.of("Ok")); + + public static RustPath ioResult(RustType okType) { + return IO_RESULT.withArgs(List.of(okType)); + } + public static RustPath SEND = RustPath.global("std", "marker", "Send"); public static RustPath SYNC = RustPath.global("std", "marker", "Sync"); |
