Skip to content

Commit

Permalink
base
Browse files Browse the repository at this point in the history
  • Loading branch information
InvalidJoker committed Aug 2, 2023
1 parent d47c144 commit 9e9764d
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 22 deletions.
6 changes: 0 additions & 6 deletions src/collection.rs

This file was deleted.

47 changes: 47 additions & 0 deletions src/container.rs
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)
}
}
6 changes: 3 additions & 3 deletions src/db.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::{fs::File, path::Path};

use crate::collection;
use crate::container;

pub struct Database {
filename: String,
collections: Vec<collection::Collection>,
collections: Vec<container::Container>,
}

impl Database {
fn read_collections() -> Vec<collection::Collection> {
fn read_collections() -> Vec<container::Container> {
unimplemented!()
}

Expand Down
7 changes: 0 additions & 7 deletions src/document.rs

This file was deleted.

27 changes: 24 additions & 3 deletions src/key.rs
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
}
}
}
7 changes: 4 additions & 3 deletions src/main.rs
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() {

}

0 comments on commit 9e9764d

Please sign in to comment.