diff options
Diffstat (limited to 'examples/03-inductive-data-types')
| -rw-r--r-- | examples/03-inductive-data-types/output/rust/src/arithmetic.rs | 10 | ||||
| -rw-r--r-- | examples/03-inductive-data-types/output/rust/src/main.rs | 14 |
2 files changed, 17 insertions, 7 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 a9679dc..d6944a9 100644 --- a/examples/03-inductive-data-types/output/rust/src/arithmetic.rs +++ b/examples/03-inductive-data-types/output/rust/src/arithmetic.rs @@ -5,6 +5,16 @@ pub enum Expression { Const(crate::arithmetic::Const), } +impl Expression { + pub fn add(value: crate::arithmetic::Add) -> Self { + Self::Add(::std::boxed::Box::new(value)) + } + + pub fn r#const(value: crate::arithmetic::Const) -> Self { + Self::Const(value) + } +} + pub struct Add { pub left: crate::arithmetic::Expression, pub right: crate::arithmetic::Expression, 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 8c1f750..28f7cec 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(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 }), - })); + 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 }), + }); } |
