summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttransient0/RustTransient0Generator.java31
1 files changed, 27 insertions, 4 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 b53345e..4a37e4a 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
@@ -259,12 +259,35 @@ public class RustTransient0Generator implements Generator {
generateReaderReadExact(RustPath.of(len))
)
),
- Optional.of(unwrap(
+ Optional.of(
+ new RustTryPropagationExpression(mapErr(
+ new RustCallExpression(
+ RustPath.global("std", "string", "String", "from_utf8"),
+ List.of(RustPath.of(bytes))
+ )
+ ))
+ )
+ )
+ );
+ }
+
+ private RustExpression mapErr(RustExpression result) {
+ var error = RustIdentifier.of("error");
+
+ return methodCall(
+ result,
+ RustIdentifier.of("map_err"),
+ List.of(
+ new RustClosureExpression(
+ List.of(new RustIdentifierPattern(error)),
new RustCallExpression(
- RustPath.global("std", "string", "String", "from_utf8"),
- List.of(RustPath.of(bytes))
+ RustPath.global("std", "io", "Error", "new"),
+ List.of(
+ RustPath.global("std", "io", "ErrorKind", "InvalidData"),
+ RustPath.of(error)
+ )
)
- ))
+ )
)
);
}