Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Enum that works like a constructed function
- enum Func {
- Add(i32, Box<Func>),
- Sub(i32, Box<Func>),
- Nil
- }
- impl Func {
- fn call(&self, value:i32) -> i32 {
- match self {
- Func::Nil => value,
- Func::Add(num, next) => next.call(value + num),
- Func::Sub(num, next) => next.call(value - num)
- }
- }
- }
- fn main() {
- let foo = Func::Add(40, Box::new(Func::Sub(3, Box::new(Func::Nil))));
- println!("{}", foo.call(5));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement