summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/02-sum/output/rust/src/shapes.rs8
-rw-r--r--examples/03-inductive-data-types/output/rust/src/arithmetic.rs8
-rw-r--r--examples/03-inductive-data-types/output/rust/src/main.rs14
3 files changed, 17 insertions, 13 deletions
diff --git a/examples/02-sum/output/rust/src/shapes.rs b/examples/02-sum/output/rust/src/shapes.rs
index 31c3db9..d5b7334 100644
--- a/examples/02-sum/output/rust/src/shapes.rs
+++ b/examples/02-sum/output/rust/src/shapes.rs
@@ -6,12 +6,14 @@ pub enum Shape {
Triangle(crate::shapes::Triangle),
}
-impl Shape {
- pub fn rectangle(value: crate::shapes::Rectangle) -> Self {
+impl ::std::convert::From<crate::shapes::Rectangle> for crate::shapes::Shape {
+ fn from(value: crate::shapes::Rectangle) -> Self {
Self::Rectangle(value)
}
+}
- pub fn triangle(value: crate::shapes::Triangle) -> Self {
+impl ::std::convert::From<crate::shapes::Triangle> for crate::shapes::Shape {
+ fn from(value: crate::shapes::Triangle) -> Self {
Self::Triangle(value)
}
}
diff --git a/examples/03-inductive-data-types/output/rust/src/arithmetic.rs b/examples/03-inductive-data-types/output/rust/src/arithmetic.rs
index d6944a9..ac7c740 100644
--- a/examples/03-inductive-data-types/output/rust/src/arithmetic.rs
+++ b/examples/03-inductive-data-types/output/rust/src/arithmetic.rs
@@ -5,12 +5,14 @@ pub enum Expression {
Const(crate::arithmetic::Const),
}
-impl Expression {
- pub fn add(value: crate::arithmetic::Add) -> Self {
+impl ::std::convert::From<crate::arithmetic::Add> for crate::arithmetic::Expression {
+ fn from(value: crate::arithmetic::Add) -> Self {
Self::Add(::std::boxed::Box::new(value))
}
+}
- pub fn r#const(value: crate::arithmetic::Const) -> Self {
+impl ::std::convert::From<crate::arithmetic::Const> for crate::arithmetic::Expression {
+ fn from(value: crate::arithmetic::Const) -> Self {
Self::Const(value)
}
}
diff --git a/examples/03-inductive-data-types/output/rust/src/main.rs b/examples/03-inductive-data-types/output/rust/src/main.rs
index 28f7cec..61fd820 100644
--- a/examples/03-inductive-data-types/output/rust/src/main.rs
+++ b/examples/03-inductive-data-types/output/rust/src/main.rs
@@ -3,11 +3,11 @@ mod arithmetic;
use arithmetic::{Add, Const, Expression};
fn main() {
- let expression = Expression::add(Add {
- left: Expression::add(Add {
- left: Expression::r#const(Const { value: 42 }),
- right: Expression::r#const(Const { value: 47 }),
- }),
- right: Expression::r#const(Const { value: 52 }),
- });
+ let expression: Expression = Add {
+ left: Add {
+ left: Const { value: 42 }.into(),
+ right: Const { value: 47 }.into(),
+ }.into(),
+ right: Const { value: 52 }.into(),
+ }.into();
}