morethantext-web/src/morethantext/mod.rs

56 lines
990 B
Rust

mod cache;
mod error;
use async_std::{
channel::{unbounded, Sender},
path::PathBuf,
task::spawn,
};
use cache::Cache;
use error::{ErrorCode, MTTError};
#[derive(Clone, Debug)]
struct Data {
id: String,
}
#[derive(Clone)]
pub struct MoreThanText {
to_cache: Sender<String>,
}
impl MoreThanText {
fn new(to_cache: Sender<String>) -> Self {
Self { to_cache: to_cache }
}
async fn session(&self) {
}
}
#[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();
mtt.session().await;
}
}
pub async fn start_db<P>(dir: P) -> Result<MoreThanText, MTTError>
where
P: Into<PathBuf>,
{
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))
}