summaryrefslogtreecommitdiff
path: root/examples/02-sum/output/rust/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-07-02 09:57:35 +0100
committerMichael Williamson <mike@zwobble.org>2026-07-02 09:57:35 +0100
commit066af00eebe662e5a589a4e274e1613201b36982 (patch)
tree985cf23c7288ca11c51611b744fd5dbde2031fa7 /examples/02-sum/output/rust/src
parent3d6034f51eba69de538ce2b7ccdd59654870db1d (diff)
Support translating sums into Rust types
Diffstat (limited to 'examples/02-sum/output/rust/src')
-rw-r--r--examples/02-sum/output/rust/src/main.rs16
-rw-r--r--examples/02-sum/output/rust/src/shapes.rs15
2 files changed, 31 insertions, 0 deletions
diff --git a/examples/02-sum/output/rust/src/main.rs b/examples/02-sum/output/rust/src/main.rs
new file mode 100644
index 0000000..010ea2a
--- /dev/null
+++ b/examples/02-sum/output/rust/src/main.rs
@@ -0,0 +1,16 @@
+mod shapes;
+
+use shapes::{Rectangle, Shape, Triangle};
+
+fn main() {
+ let shape = create_shape();
+
+ let area = match shape {
+ Shape::Rectangle(rectangle) => rectangle.width * rectangle.height,
+ Shape::Triangle(triangle) => triangle.width * triangle.height / 2,
+ };
+}
+
+fn create_shape() -> Shape {
+ Shape::Rectangle(Rectangle { width: 10, height: 25 })
+}
diff --git a/examples/02-sum/output/rust/src/shapes.rs b/examples/02-sum/output/rust/src/shapes.rs
new file mode 100644
index 0000000..9bb32f4
--- /dev/null
+++ b/examples/02-sum/output/rust/src/shapes.rs
@@ -0,0 +1,15 @@
+/// A 2D shape.
+pub enum Shape {
+ Rectangle(crate::shapes::Rectangle),
+ Triangle(crate::shapes::Triangle),
+}
+
+pub struct Rectangle {
+ pub width: i32,
+ pub height: i32,
+}
+
+pub struct Triangle {
+ pub width: i32,
+ pub height: i32,
+}