diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-24 18:05:02 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-24 18:05:02 +0100 |
| commit | 2409a40985dad843fe25611c9cd14afdac6d67bf (patch) | |
| tree | d9ba9fb0a542eba85a0c6aa35e57bfb21ac39600 | |
| parent | 2bc23bdc7fe01fc5921be8e09f405a8a1fd7bd65 (diff) | |
Support Shared in rust-types
9 files changed, 56 insertions, 7 deletions
diff --git a/examples/08-shared/hobgoblin.json5 b/examples/08-shared/hobgoblin.json5 index f9f6597..19e0f93 100644 --- a/examples/08-shared/hobgoblin.json5 +++ b/examples/08-shared/hobgoblin.json5 @@ -14,6 +14,10 @@ generator: "java-precisely-matchers", path: "output/java/src/gen/java", }, + { + generator: "rust-types", + path: "output/rust/src", + }, ], } } diff --git a/examples/08-shared/output/java/src/test/java/org/zwobble/example/PointTests.java b/examples/08-shared/output/java/src/test/java/org/zwobble/example/PointTests.java index 18a1961..b4c140d 100644 --- a/examples/08-shared/output/java/src/test/java/org/zwobble/example/PointTests.java +++ b/examples/08-shared/output/java/src/test/java/org/zwobble/example/PointTests.java @@ -2,15 +2,14 @@ package org.zwobble.example; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; +import org.zwobble.example.types.point.Line; import org.zwobble.example.types.point.Point; public class PointTests { @Test - public void pointFields() { - Point point = new Point(10, 25); - int x = point.x(); - int y = point.y(); - assertEquals(x, 10); - assertEquals(y, 25); + public void line() { + var point = new Point(10, 25); + var line = new Line(point, point); + assertEquals(line.start().x(), 10); } } diff --git a/examples/08-shared/output/rust/.gitignore b/examples/08-shared/output/rust/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/examples/08-shared/output/rust/.gitignore @@ -0,0 +1 @@ +/target diff --git a/examples/08-shared/output/rust/Cargo.lock b/examples/08-shared/output/rust/Cargo.lock new file mode 100644 index 0000000..9dc6e3e --- /dev/null +++ b/examples/08-shared/output/rust/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "example" +version = "0.1.0" diff --git a/examples/08-shared/output/rust/Cargo.toml b/examples/08-shared/output/rust/Cargo.toml new file mode 100644 index 0000000..5d4c622 --- /dev/null +++ b/examples/08-shared/output/rust/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "example" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/examples/08-shared/output/rust/rust-toolchain.toml b/examples/08-shared/output/rust/rust-toolchain.toml new file mode 100644 index 0000000..4fedb95 --- /dev/null +++ b/examples/08-shared/output/rust/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.96" diff --git a/examples/08-shared/output/rust/src/lib.rs b/examples/08-shared/output/rust/src/lib.rs new file mode 100644 index 0000000..af2c87f --- /dev/null +++ b/examples/08-shared/output/rust/src/lib.rs @@ -0,0 +1,14 @@ +mod point; + +#[cfg(test)] +mod test { + use std::sync::Arc; + use super::point::{Line, Point}; + + #[test] + fn line() { + let point = Arc::new(Point { x: 10, y: 25 }); + let line = Line { start: Arc::clone(&point), end: point }; + assert_eq!(line.start.x, 10); + } +} diff --git a/examples/08-shared/output/rust/src/point.rs b/examples/08-shared/output/rust/src/point.rs new file mode 100644 index 0000000..ef7593b --- /dev/null +++ b/examples/08-shared/output/rust/src/point.rs @@ -0,0 +1,15 @@ +// Generated by hobgoblin. + +/// A straight line from one point to another. +#[derive(Debug, PartialEq)] +pub struct Line { + pub start: ::std::sync::Arc::<crate::point::Point>, + pub end: ::std::sync::Arc::<crate::point::Point>, +} + +/// A 2D point. +#[derive(Debug, PartialEq)] +pub struct Point { + pub x: ::core::primitive::i32, + pub y: ::core::primitive::i32, +} diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rust/RustGeneratorConfig.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rust/RustGeneratorConfig.java index 7a6af2d..db5fae0 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rust/RustGeneratorConfig.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rust/RustGeneratorConfig.java @@ -56,7 +56,8 @@ public record RustGeneratorConfig( Map.entry(NativeTypes.INT_64, new RustNativeTypeConfig(RustPath.primitive("i64"))), Map.entry(NativeTypes.STRING, new RustNativeTypeConfig(RustPath.global("std", "string", "String"))), Map.entry(NativeTypes.LIST_INNER, new RustNativeTypeConfig(RustPath.global("std", "vec", "Vec"))), - Map.entry(NativeTypes.OPTION_INNER, new RustNativeTypeConfig(RustPath.global("std", "option", "Option"))) + Map.entry(NativeTypes.OPTION_INNER, new RustNativeTypeConfig(RustPath.global("std", "option", "Option"))), + Map.entry(NativeTypes.SHARED_INNER, new RustNativeTypeConfig(RustPath.global("std", "sync", "Arc"))) ); public Optional<RustNativeTypeConfig> nativeTypeConfig(SimpleNativeType type) { |
