From 1f36848450fd395c001fb256886efa8b78a51f24 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Tue, 21 Mar 2023 18:35:42 -0400 Subject: [PATCH] Moved in new mod file. --- src/morethantext/mod.rs | 36 ++++++++++++++++++++++++++++-------- src/morethantext/session.rs | 0 2 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 src/morethantext/session.rs diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index 05bb3b8..6aa2f6e 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -1,17 +1,34 @@ -use super::{DBError, Database, ErrorCode, FileData, SessionData, Store}; +mod database; +mod error; +mod store; + use async_std::{ fs::{read, remove_file, write}, path::{Path, PathBuf}, }; +use database::Database; +use error::{DBError, ErrorCode}; use rand::{distributions::Alphanumeric, thread_rng, Rng}; use std::{ cell::Cell, slice, str, time::{Duration, Instant}, }; +use store::Store; const ENTRY: &str = "EntryPoint"; +trait FileData { + fn to_bytes(&self) -> Vec; + fn from_bytes(data: &mut slice::Iter) -> Result; +} + +trait SessionData { + fn add(&mut self, key: &str, value: &str, data: &str) -> Result, DBError>; + fn eq(&self, key: &str, value: &str) -> Result, DBError>; + fn list(&self, keys: Vec<&str>) -> Result, DBError>; +} + #[derive(Clone)] enum DataType { DBMap(Store), @@ -192,10 +209,11 @@ impl Entry { } } -struct Cache; +#[derive(Clone)] +pub struct MoreThanText; -impl Cache { - async fn new

(dir: P) -> Result +impl MoreThanText { + pub async fn new

(dir: P) -> Result where P: Into, { @@ -662,7 +680,9 @@ mod cache { #[async_std::test] async fn create() { let dir = tempdir().unwrap(); - Cache::new(dir.path().to_str().unwrap()).await.unwrap(); + MoreThanText::new(dir.path().to_str().unwrap()) + .await + .unwrap(); let epoint = dir.path().join(ENTRY); assert!( epoint.is_file(), @@ -680,7 +700,7 @@ mod cache { async fn entry_failure() -> Result<(), DBError> { let dir = tempdir().unwrap(); let path = dir.path().join("bad").join("path"); - match Cache::new(path).await { + match MoreThanText::new(path).await { Ok(_) => Err(DBError::new("Should have produced an error.")), Err(err) => match err.code { ErrorCode::CacheReadWrite => { @@ -704,7 +724,7 @@ mod cache { Entry::new(dir.path().join(ENTRY), data.clone()) .await .unwrap(); - let cache = Cache::new(dir.path()).await.unwrap(); + let cache = MoreThanText::new(dir.path()).await.unwrap(); } #[async_std::test] @@ -712,7 +732,7 @@ mod cache { let dir = tempdir().unwrap(); let file = dir.path().join(ENTRY); write(file, b"Really bad data.").await.unwrap(); - match Cache::new(dir.path()).await { + match MoreThanText::new(dir.path()).await { Ok(_) => Err(DBError::new("should have errored")), Err(_) => Ok(()), } diff --git a/src/morethantext/session.rs b/src/morethantext/session.rs new file mode 100644 index 0000000..e69de29