DEV Community

loading...

Discussion on: First thoughts on Rust vs OCaml

Collapse
wpwoodjr profile image
Bill Wood

I think this would be more idiomatic for your enum, and also shows how to match on a Box:
play.rust-lang.org/?version=stable...

#[derive(Debug)]
pub enum Expr_ {
  Let(String, Expr, Expr),
  FnCall(String, Vec<Expr>),
  Lambda(Vec<String>, Expr),
  Variable(String),
  IntLiteral(i32),
}
use self::Expr_::*;

pub type Expr = Box<Expr_>;

fn main() {
    let x = Box::new(Variable("test".to_string()));
    match *x {
        Variable(n) => dbg!(n),
        _ => unimplemented!()
    };
}