From f222af6b5e38fcbf876c3213016e298bf590b60a Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 18 Jul 2026 18:58:24 +0100 Subject: Extract tryIntoOrUnwrap() --- .../rusttransient0/RustTransient0Generator.java | 41 ++++++++++------------ 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'src/main') 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() + ); + } } -- cgit v1.2.3