-
-
Save greister/5a60fc28e85ccc6faabd73dc789c5570 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
pub trait Ast {
fn evaluate(&mut self) -> Option<Box>;
}
pub struct Assignment<'a> {
lhs: Option<Box<Ast + 'a>>,
rhs: Option<Box<Ast + 'a>>
}
impl<'a> Ast for Assignment<'a> {
}
fn main() {
println!("Foo");
// let ass = Assignment{lhs: Some(Box::new(var)), rhs: None};
//let maybe = ass.evaluate();
}