Created
April 17, 2016 14:37
-
-
Save anonymous/f2521c7c10777ce112ae4dfe1b87defb to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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