-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d47c144
commit 9e9764d
Showing
6 changed files
with
78 additions
and
22 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use hashbrown::HashMap; | ||
|
||
use crate::key::Key; | ||
|
||
pub struct Container { | ||
name: String, | ||
documents: Vec<HashMap<String, Key>>, | ||
} | ||
|
||
/* | ||
Container { | ||
"TestContainer", | ||
{ | ||
aaron: { | ||
name: "Aaron", | ||
age: 20, | ||
}, | ||
bob: { | ||
name: "Bob", | ||
age: 21, | ||
}, | ||
carl: { | ||
name: "Carl", | ||
age: 22, | ||
}, | ||
} | ||
} | ||
*/ | ||
|
||
impl Container { | ||
pub fn new(name: String) -> Self { | ||
Container { | ||
name, | ||
documents: Vec::new(), | ||
} | ||
} | ||
|
||
pub fn add_document(&mut self, name: String, key: Key) { | ||
let mut document = HashMap::new(); | ||
document.insert(name, key); | ||
self.documents.push(document); | ||
} | ||
|
||
pub fn get_document(&self, index: usize) -> Option<&HashMap<String, Key>> { | ||
self.documents.get(index) | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
#[derive(Debug)] | ||
use std::collections::HashMap; | ||
use std::any::Any; | ||
|
||
pub struct Key { | ||
key: String, | ||
value: String, | ||
data: HashMap<String, Box<dyn Any>>, | ||
} | ||
|
||
impl Key { | ||
pub fn new() -> Self { | ||
Key { | ||
data: HashMap::new(), | ||
} | ||
} | ||
|
||
pub fn insert<T: Any + 'static>(&mut self, key: String, value: T) { | ||
self.data.insert(key, Box::new(value)); | ||
} | ||
|
||
pub fn get<T: Any + 'static>(&self, key: &str) -> Option<&T> { | ||
if let Some(value) = self.data.get(key) { | ||
value.downcast_ref::<T>() | ||
} else { | ||
None | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
mod collection; | ||
mod container; | ||
mod db; | ||
mod document; | ||
mod key; | ||
|
||
fn main() {} | ||
fn main() { | ||
|
||
} |