Skip to content

Instantly share code, notes, and snippets.

Created April 17, 2016 14:37
Show Gist options
  • Save anonymous/f2521c7c10777ce112ae4dfe1b87defb to your computer and use it in GitHub Desktop.
Save anonymous/f2521c7c10777ce112ae4dfe1b87defb to your computer and use it in GitHub Desktop.
Shared via Rust Playground
pub trait Ast<'a> {
fn evaluate(self: Box<Self>) -> Option<Box<Ast<'a> + 'a>>;
}
pub struct Assignment<'a> {
lhs: Option<Box<Ast<'a> + 'a>>,
rhs: Option<Box<Ast<'a> + 'a>>
}
impl<'a> Ast<'a> for Assignment<'a> {
fn evaluate(mut self: Box<Self>) -> Option<Box<Ast<'a> + 'a>>{
println!("Eval assignment");
let evaluated = self.lhs.take().unwrap().evaluate();
self.lhs = evaluated;
Some(self)
}
}
fn main() {
println!("Foo");
//let var = Var{var_id: "X"};
// let ass = Assignment{lhs: Some(Box::new(var)), rhs: None};
//let maybe = ass.evaluate();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment