From aaca617dea0adc0ce5cc535ac969bb8e123ba9ca Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 26 Jul 2026 11:55:32 +0100 Subject: Remove duplication of mapping error to InvalidData --- .../rusttransient0/RustTransient0Generator.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'src') 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 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) ) ) ); -- cgit v1.2.3