diff options
Diffstat (limited to 'examples/03-inductive-data-types')
| -rw-r--r-- | examples/03-inductive-data-types/output/rust/src/arithmetic.rs | 8 | ||||
| -rw-r--r-- | examples/03-inductive-data-types/output/rust/src/main.rs | 14 |
2 files changed, 12 insertions, 10 deletions
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(); } |
