diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-17 17:28:29 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-17 17:28:29 +0100 |
| commit | 1bb360ac2e866bebdb05c5324d31c2487add1b50 (patch) | |
| tree | b483364943b41318cf8d0db218b8de22335838f7 | |
| parent | e830f34ceb4401ca423740f843835db057ee7411 (diff) | |
Pass list of statements to generateEncodeFunction
| -rw-r--r-- | src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java | 77 |
1 files changed, 34 insertions, 43 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 950c2ac..8405232 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 @@ -83,11 +83,8 @@ public class RustTransient0Generator implements Generator { private RustItem generateEncodeBoolFunction() { return generateEncodeFunction( NativeTypes.BOOL, - new RustBlockExpression( - List.of( - new RustExpressionStatement(generateTodo()) - ), - Optional.empty() + List.of( + new RustExpressionStatement(generateTodo()) ) ); } @@ -121,22 +118,19 @@ public class RustTransient0Generator implements Generator { private RustItem generateEncodeIntFunction(SimpleNativeType type) { return generateEncodeFunction( type, - new RustBlockExpression( - List.of( - new RustExpressionStatement( - generateWriterWrite(new RustPrefixExpression( - RustPrefixOperator.BORROW, - new RustCallExpression( - new RustFieldExpression( - RustPath.of(VALUE_NAME), - RustIdentifier.of("to_le_bytes") - ), - List.of() - ) - )) - ) - ), - Optional.empty() + List.of( + new RustExpressionStatement( + generateWriterWrite(new RustPrefixExpression( + RustPrefixOperator.BORROW, + new RustCallExpression( + new RustFieldExpression( + RustPath.of(VALUE_NAME), + RustIdentifier.of("to_le_bytes") + ), + List.of() + ) + )) + ) ) ); } @@ -166,11 +160,8 @@ public class RustTransient0Generator implements Generator { private RustItem generateEncodeStringFunction() { return generateEncodeFunction( NativeTypes.STRING, - new RustBlockExpression( - List.of( - new RustExpressionStatement(generateTodo()) - ), - Optional.empty() + List.of( + new RustExpressionStatement(generateTodo()) ) ); } @@ -221,21 +212,18 @@ public class RustTransient0Generator implements Generator { yield Stream.of( generateEncodeFunction( structDefinition.type(), - new RustBlockExpression( - structDefinition.fields().stream() - .flatMap(field -> generateEncode( - new RustPrefixExpression( - RustPrefixOperator.BORROW, - new RustFieldExpression( - RustPath.of(VALUE_NAME), - this.rustGenerator.generateFieldName(field.name()) - ) - ), - field.type().value() - ).stream()) - .toList(), - Optional.empty() - ) + structDefinition.fields().stream() + .flatMap(field -> generateEncode( + new RustPrefixExpression( + RustPrefixOperator.BORROW, + new RustFieldExpression( + RustPath.of(VALUE_NAME), + this.rustGenerator.generateFieldName(field.name()) + ) + ), + field.type().value() + ).stream()) + .toList() ), generateDecodeFunction( structDefinition.type(), @@ -269,7 +257,7 @@ public class RustTransient0Generator implements Generator { private RustItem generateEncodeFunction( Type type, - RustBlockExpression body + List<RustStatement> body ) { var rustType = this.rustGenerator.generateRustTypeExpression(type); @@ -281,7 +269,10 @@ public class RustTransient0Generator implements Generator { new RustFunctionParam(WRITER_NAME, new RustMutableReferenceType(new RustImplTraitType(RustPath.of("std", "io", "Write")))) ), Optional.empty(), - Optional.of(body) + Optional.of(new RustBlockExpression( + body, + Optional.empty() + )) ); } |
