Created
November 10, 2019 03:54
-
-
Save samrat/56493c4adfa513b733718eef0d3b06e2 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::collections::HashMap; | |
struct Database { | |
objects: HashMap<String, Object>, | |
} | |
enum Object { | |
Tree, | |
Commit { tree_id: String }, | |
} | |
impl Database { | |
fn load(&mut self, object_id: &str) -> &Object { | |
self.objects | |
.get(object_id) | |
.expect("did not find object") | |
} | |
fn load_tree(&mut self, object_id: &str) -> &Object { | |
match self.load(object_id) { | |
Object::Tree => &Object::Tree, | |
Object::Commit { tree_id } => self.load(&tree_id), | |
} | |
} | |
} | |
fn main() {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment