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 | 41 |
1 files changed, 18 insertions, 23 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 f5e1f25..6d24c0a 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 @@ -219,20 +219,11 @@ public class RustTransient0Generator implements Generator { generateEncode( new RustPrefixExpression( RustPrefixOperator.BORROW, - methodCall( - methodCall( - methodCall( - RustPath.of(VALUE_NAME), - RustIdentifier.of("len"), - List.of() - ), - RustIdentifier.of("try_into"), - List.of() - ), - // TODO: remove unwrap - RustIdentifier.of("unwrap"), + tryIntoOrUnwrap(methodCall( + RustPath.of(VALUE_NAME), + RustIdentifier.of("len"), List.of() - ) + )) ), NativeTypes.INT_64 ), @@ -549,16 +540,7 @@ public class RustTransient0Generator implements Generator { var bytes = RustIdentifier.of("bytes"); // TODO: extract into let - var lengthUsize = methodCall( - methodCall( - length, - RustIdentifier.of("try_into"), - List.of() - ), - // TODO: remove unwrap - RustIdentifier.of("unwrap"), - List.of() - ); + var lengthUsize = tryIntoOrUnwrap(length); return new RustBlockExpression( List.of( @@ -613,4 +595,17 @@ public class RustTransient0Generator implements Generator { args ); } + + private RustExpression tryIntoOrUnwrap(RustExpression value) { + return methodCall( + methodCall( + value, + RustIdentifier.of("try_into"), + List.of() + ), + // TODO: remove unwrap + RustIdentifier.of("unwrap"), + List.of() + ); + } } |
