diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-26 11:55:32 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-26 11:55:32 +0100 |
| commit | aaca617dea0adc0ce5cc535ac969bb8e123ba9ca (patch) | |
| tree | 9ff9fc9420718faf82db6b2ea629dcb70f374f91 /src/main/java/org/zwobble | |
| parent | 6e73cc0501e63fe9361b24a20d70a5a18857ef0d (diff) | |
Remove duplication of mapping error to InvalidData
Diffstat (limited to 'src/main/java/org/zwobble')
| -rw-r--r-- | src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java | 19 |
1 files changed, 10 insertions, 9 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 6f8de50..3718f05 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 @@ -898,7 +898,7 @@ public class RustTransient0Generator implements Generator { new RustBlockExpression( List.of(), Optional.of( - new RustTryPropagationExpression(mapErr( + new RustTryPropagationExpression(mapErrToInvalidData( methodCall( new RustCallExpression( RustTypes.ARC.addSegment(RustPathSegment.of("clone")), @@ -913,13 +913,7 @@ public class RustTransient0Generator implements Generator { RustIdentifier.of("downcast"), List.of() ), - _ -> new RustCallExpression( - RustPath.global("std", "io", "Error", "new"), - List.of( - RustPath.global("std", "io", "ErrorKind", "InvalidData"), - new RustStringLiteral("referenced value has wrong type") - ) - ) + _ -> new RustStringLiteral("referenced value has wrong type") )) ) ), @@ -1066,13 +1060,20 @@ public class RustTransient0Generator implements Generator { } private RustExpression mapErrToInvalidData(RustExpression result) { + return mapErrToInvalidData(result, error -> RustPath.of(error)); + } + + private RustExpression mapErrToInvalidData( + RustExpression result, + Function<RustIdentifier, RustExpression> createSubError + ) { return mapErr( result, error -> new RustCallExpression( RustPath.global("std", "io", "Error", "new"), List.of( RustPath.global("std", "io", "ErrorKind", "InvalidData"), - RustPath.of(error) + createSubError.apply(error) ) ) ); |
