diff options
Diffstat (limited to 'src/main/java/org/zwobble')
| -rw-r--r-- | src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java | 35 |
1 files changed, 23 insertions, 12 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 8405232..8fc9b61 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 @@ -268,10 +268,18 @@ public class RustTransient0Generator implements Generator { new RustFunctionParam(VALUE_NAME, new RustSharedReferenceType(rustType)), new RustFunctionParam(WRITER_NAME, new RustMutableReferenceType(new RustImplTraitType(RustPath.of("std", "io", "Write")))) ), - Optional.empty(), + Optional.of( + RustPath.global("std", "io", "Result") + .withArgs(List.of(new RustTupleType(List.of()))) + ), Optional.of(new RustBlockExpression( body, - Optional.empty() + Optional.of( + new RustCallExpression( + RustPath.global("std", "io", "Result", "Ok"), + List.of(new RustTupleExpression(List.of())) + ) + ) )) ); } @@ -288,8 +296,11 @@ public class RustTransient0Generator implements Generator { List.of( new RustFunctionParam(READER_NAME, new RustMutableReferenceType(new RustImplTraitType(RustPath.of("std", "io", "Read")))) ), - Optional.of(rustType), - Optional.of(body) + Optional.of(RustPath.global("std", "io", "Result").withArgs(List.of(rustType))), + Optional.of(new RustBlockExpression( + body.statements(), + body.finalOperand().map(finalOperand -> new RustCallExpression(RustPath.of("std", "io", "Result", "Ok"), List.of(finalOperand))) + )) ); } @@ -367,10 +378,10 @@ public class RustTransient0Generator implements Generator { ); return List.of( - new RustExpressionStatement(new RustCallExpression( + new RustExpressionStatement(new RustTryPropagationExpression(new RustCallExpression( rustEncodeFunctionPath, List.of(value, RustPath.of(WRITER_NAME)) - )) + ))) ); } @@ -383,20 +394,20 @@ public class RustTransient0Generator implements Generator { rustDecodeFunctionPathSegments ); - return new RustCallExpression( + return new RustTryPropagationExpression(new RustCallExpression( rustDecodeFunctionPath, List.of(RustPath.of(READER_NAME)) - ); + )); } private RustExpression generateWriterWrite(RustExpression valueToWrite) { - return new RustCallExpression( + return new RustTryPropagationExpression(new RustCallExpression( new RustFieldExpression( RustPath.of(WRITER_NAME), RustIdentifier.of("write_all") ), List.of(valueToWrite) - ); + )); } private RustExpression generateReaderReadExact(int length) { @@ -412,7 +423,7 @@ public class RustTransient0Generator implements Generator { new RustIntegerLiteral(length) ) ), - new RustExpressionStatement(new RustCallExpression( + new RustExpressionStatement(new RustTryPropagationExpression(new RustCallExpression( new RustFieldExpression( RustPath.of(READER_NAME), RustIdentifier.of("read_exact") @@ -423,7 +434,7 @@ public class RustTransient0Generator implements Generator { RustPath.of(bytes) ) ) - )) + ))) ), Optional.of(RustPath.of(bytes)) ); |
