Created
July 28, 2013 23:33
-
-
Save jmgrosen/6100721 to your computer and use it in GitHub Desktop.
This file contains 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
use std::hashmap::HashMap; | |
enum Thing { Foo, Bar } | |
struct Context<'self> { | |
scope: HashMap<&'self str, Thing>, | |
parent: &'self Option<Context<'self>> | |
} | |
impl<'self> Context<'self> { | |
fn get(&self, identifier: &str) -> Option<&'self Thing> { | |
match self.scope.find_equiv(&identifier) { | |
Some(thing) => Some(thing), | |
None => match (*self.parent) { | |
Some(parent) => parent.get(identifier), | |
None => None | |
} | |
} | |
} | |
} | |
fn main() {} |
Author
jmgrosen
commented
Jul 28, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment