Skip to content

Instantly share code, notes, and snippets.

@samrat
Created November 10, 2019 03:54
Show Gist options
  • Save samrat/56493c4adfa513b733718eef0d3b06e2 to your computer and use it in GitHub Desktop.
Save samrat/56493c4adfa513b733718eef0d3b06e2 to your computer and use it in GitHub Desktop.
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