mod cache; mod error; mod store; use async_std::{ channel::{unbounded, Sender}, path::PathBuf, task::spawn, }; use cache::Cache; use error::{ErrorCode, MTTError}; use store::Store; const ENTRY: &str = "EntryPoint"; #[derive(Clone, Debug)] struct Data { id: Option, data: Option, } impl Data { fn from_id(id: S) -> Self where S: Into, { Self { id: Some(id.into()), data: None, } } } #[derive(Clone)] pub struct MoreThanText { to_cache: Sender, entry: Data, } impl MoreThanText { fn new(to_cache: Sender) -> Self { Self { to_cache: to_cache, entry: Data::from_id(ENTRY), } } async fn session(&self) -> Store { Store::new() } } #[cfg(test)] mod mtt { use super::*; use tempfile::tempdir; #[async_std::test] async fn create_new() { let dir = tempdir().unwrap(); let mtt = start_db(dir.path()).await.unwrap(); assert_eq!(mtt.entry.id, Some(ENTRY.to_string())); assert!(mtt.entry.data.is_none()); let store = mtt.session().await; let expected: Vec = Vec::new(); assert_eq!(store.list(), expected); } } pub async fn start_db

(dir: P) -> Result where P: Into, { let path = dir.into(); let (s, r) = unbounded(); spawn(async move { let cache = Cache::new(path).await; cache.listen(r).await; }); Ok(MoreThanText::new(s)) }