Skip to content

Commit

Permalink
Added embedded storage.
Browse files Browse the repository at this point in the history
  • Loading branch information
denzyldick committed Feb 19, 2023
1 parent 13d3835 commit d820573
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use std::fmt::Debug;

use crate::rules::File;
use rocksdb::{DBCommon, Options, SingleThreaded, DB};
use serde::{Deserialize, Serialize};

pub fn put<T: Serialize + Debug>(db: &DB, key: String, file: T) {
let bytes = match serde_json::to_string(&file) {
Ok(o) => {
match db.put(key, o) {
Err(e) => {
// println!("Helloworld");
// println!("{file:?}");
// println!("{e}");
}
Ok(ok) => {}
};
}
Err(e) => {
// println!("{file:?}");
// print!("{e}");
}
};
}
pub fn get(db: &DB, key: String) -> Option<File> {
let path = "/tmp";

match db.get(key) {
Ok(Some(f)) => {
let file = serde_json::from_slice(&f).unwrap();
Some(file)
}

Err(e) => {
println!("{e}");
None
}
_ => None,
}
}

0 comments on commit d820573

Please sign in to comment.