diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-02 16:49:54 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-02 16:49:54 +0100 |
| commit | 6d87397a04e0cd35a5560b50de37c3a3ed550af0 (patch) | |
| tree | ea290d5ff2247b62fa0bc46280e8b366983324da /examples/03-inductive-data-types | |
| parent | 94d481c940fb36da896e2e80a62f39d849477f53 (diff) | |
Handle boxing in Rust output
Diffstat (limited to 'examples/03-inductive-data-types')
7 files changed, 48 insertions, 0 deletions
diff --git a/examples/03-inductive-data-types/hobgoblin.json5 b/examples/03-inductive-data-types/hobgoblin.json5 index 28269ad..12713d4 100644 --- a/examples/03-inductive-data-types/hobgoblin.json5 +++ b/examples/03-inductive-data-types/hobgoblin.json5 @@ -10,6 +10,10 @@ generator: "java-types", path: "output/java/src/gen/java", }, + { + generator: "rust-types", + path: "output/rust/src", + }, ], }, } diff --git a/examples/03-inductive-data-types/output/rust/.gitignore b/examples/03-inductive-data-types/output/rust/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/examples/03-inductive-data-types/output/rust/.gitignore @@ -0,0 +1 @@ +/target diff --git a/examples/03-inductive-data-types/output/rust/Cargo.lock b/examples/03-inductive-data-types/output/rust/Cargo.lock new file mode 100644 index 0000000..9dc6e3e --- /dev/null +++ b/examples/03-inductive-data-types/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/03-inductive-data-types/output/rust/Cargo.toml b/examples/03-inductive-data-types/output/rust/Cargo.toml new file mode 100644 index 0000000..5d4c622 --- /dev/null +++ b/examples/03-inductive-data-types/output/rust/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "example" +version = "0.1.0" +edition = "2024" + +[dependencies] diff --git a/examples/03-inductive-data-types/output/rust/rust-toolchain.toml b/examples/03-inductive-data-types/output/rust/rust-toolchain.toml new file mode 100644 index 0000000..4fedb95 --- /dev/null +++ b/examples/03-inductive-data-types/output/rust/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.96" diff --git a/examples/03-inductive-data-types/output/rust/src/arithmetic.rs b/examples/03-inductive-data-types/output/rust/src/arithmetic.rs new file mode 100644 index 0000000..ab4049d --- /dev/null +++ b/examples/03-inductive-data-types/output/rust/src/arithmetic.rs @@ -0,0 +1,15 @@ +// Generated by hobgoblin. + +pub enum Expression { + Add(std::boxed::Box<crate::arithmetic::Add>), + Const(crate::arithmetic::Const), +} + +pub struct Add { + pub left: crate::arithmetic::Expression, + pub right: crate::arithmetic::Expression, +} + +pub struct Const { + pub value: i32, +} diff --git a/examples/03-inductive-data-types/output/rust/src/main.rs b/examples/03-inductive-data-types/output/rust/src/main.rs new file mode 100644 index 0000000..8c1f750 --- /dev/null +++ b/examples/03-inductive-data-types/output/rust/src/main.rs @@ -0,0 +1,13 @@ +mod arithmetic; + +use arithmetic::{Add, Const, Expression}; + +fn main() { + let expression = Expression::Add(Box::new(Add { + left: Expression::Add(Box::new(Add { + left: Expression::Const(Const { value: 42 }), + right: Expression::Const(Const { value: 47 }), + })), + right: Expression::Const(Const { value: 52 }), + })); +} |
