Moved in new mod file.

This commit is contained in:
Jeff Baskin 2023-03-21 18:35:42 -04:00
parent d4d42a599e
commit 1f36848450
2 changed files with 28 additions and 8 deletions

View File

@ -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<F> {
fn to_bytes(&self) -> Vec<u8>;
fn from_bytes(data: &mut slice::Iter<u8>) -> Result<F, DBError>;
}
trait SessionData {
fn add(&mut self, key: &str, value: &str, data: &str) -> Result<Vec<String>, DBError>;
fn eq(&self, key: &str, value: &str) -> Result<Vec<String>, DBError>;
fn list(&self, keys: Vec<&str>) -> Result<Vec<String>, 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<P>(dir: P) -> Result<Self, DBError>
impl MoreThanText {
pub async fn new<P>(dir: P) -> Result<Self, DBError>
where
P: Into<PathBuf>,
{
@ -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(()),
}

View File