diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-18 18:58:24 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-18 18:58:24 +0100 |
| commit | f222af6b5e38fcbf876c3213016e298bf590b60a (patch) | |
| tree | c202054c5ffd75bee3d15365aee7780eb307b452 /src/main/java/org | |
| parent | b801471a3555e81f59e60d34707cb0fd9b0864d8 (diff) | |
Extract tryIntoOrUnwrap()
Diffstat (limited to 'src/main/java/org')
| -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() + ); + } } |
