From 9e9764dd187be136f09893b84e46c972d3f3ce70 Mon Sep 17 00:00:00 2001 From: InvalidJokerDE <83445245+InvalidJokerDE@users.noreply.github.com> Date: Wed, 2 Aug 2023 13:54:14 +0200 Subject: [PATCH] base --- src/collection.rs | 6 ------ src/container.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/db.rs | 6 +++--- src/document.rs | 7 ------- src/key.rs | 27 ++++++++++++++++++++++++--- src/main.rs | 7 ++++--- 6 files changed, 78 insertions(+), 22 deletions(-) delete mode 100644 src/collection.rs create mode 100644 src/container.rs delete mode 100644 src/document.rs diff --git a/src/collection.rs b/src/collection.rs deleted file mode 100644 index 2fa6b87..0000000 --- a/src/collection.rs +++ /dev/null @@ -1,6 +0,0 @@ -use crate::document; - -pub struct Collection { - name: String, - documents: Vec, -} diff --git a/src/container.rs b/src/container.rs new file mode 100644 index 0000000..e3beb6a --- /dev/null +++ b/src/container.rs @@ -0,0 +1,47 @@ +use hashbrown::HashMap; + +use crate::key::Key; + +pub struct Container { + name: String, + documents: Vec>, +} + +/* +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> { + self.documents.get(index) + } +} diff --git a/src/db.rs b/src/db.rs index 0491878..1303c71 100644 --- a/src/db.rs +++ b/src/db.rs @@ -1,14 +1,14 @@ use std::{fs::File, path::Path}; -use crate::collection; +use crate::container; pub struct Database { filename: String, - collections: Vec, + collections: Vec, } impl Database { - fn read_collections() -> Vec { + fn read_collections() -> Vec { unimplemented!() } diff --git a/src/document.rs b/src/document.rs deleted file mode 100644 index 5d627a7..0000000 --- a/src/document.rs +++ /dev/null @@ -1,7 +0,0 @@ -use crate::key; - -#[derive(Debug)] -pub struct Document { - id: i32, - keys: Vec, -} diff --git a/src/key.rs b/src/key.rs index 5d900c2..0d87f7e 100644 --- a/src/key.rs +++ b/src/key.rs @@ -1,5 +1,26 @@ -#[derive(Debug)] +use std::collections::HashMap; +use std::any::Any; + pub struct Key { - key: String, - value: String, + data: HashMap>, } + +impl Key { + pub fn new() -> Self { + Key { + data: HashMap::new(), + } + } + + pub fn insert(&mut self, key: String, value: T) { + self.data.insert(key, Box::new(value)); + } + + pub fn get(&self, key: &str) -> Option<&T> { + if let Some(value) = self.data.get(key) { + value.downcast_ref::() + } else { + None + } + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index cfd8d7f..03141ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ -mod collection; +mod container; mod db; -mod document; mod key; -fn main() {} +fn main() { + +}