morethantext-web/src/morethantext/mod.rs

56 lines
990 B
Rust
Raw Normal View History

2023-05-29 15:42:32 -04:00
mod cache;
mod error;
2023-04-04 09:59:29 -04:00
use async_std::{
2023-05-29 15:42:32 -04:00
channel::{unbounded, Sender},
2023-04-04 09:59:29 -04:00
path::PathBuf,
task::spawn,
};
2023-05-29 15:42:32 -04:00
use cache::Cache;
use error::{ErrorCode, MTTError};
#[derive(Clone, Debug)]
2023-05-29 15:42:32 -04:00
struct Data {
id: String,
2023-04-08 15:04:04 -04:00
}
2023-04-04 09:59:29 -04:00
#[derive(Clone)]
pub struct MoreThanText {
2023-05-29 15:42:32 -04:00
to_cache: Sender<String>,
2023-04-04 09:59:29 -04:00
}
impl MoreThanText {
2023-05-29 15:42:32 -04:00
fn new(to_cache: Sender<String>) -> Self {
Self { to_cache: to_cache }
2023-04-12 18:33:39 -04:00
}
2023-05-29 15:42:32 -04:00
async fn session(&self) {
2023-04-08 15:04:04 -04:00
}
}
#[cfg(test)]
2023-05-29 15:42:32 -04:00
mod mtt {
2023-04-08 15:04:04 -04:00
use super::*;
use tempfile::tempdir;
2023-04-18 09:02:18 -04:00
#[async_std::test]
2023-05-29 15:42:32 -04:00
async fn create_new() {
2023-04-18 09:02:18 -04:00
let dir = tempdir().unwrap();
2023-05-29 15:42:32 -04:00
let mtt = start_db(dir.path()).await.unwrap();
mtt.session().await;
2023-04-12 18:33:39 -04:00
}
2023-04-04 12:36:10 -04:00
}
2023-05-29 15:42:32 -04:00
pub async fn start_db<P>(dir: P) -> Result<MoreThanText, MTTError>
2023-04-04 09:59:29 -04:00
where
P: Into<PathBuf>,
{
2023-05-29 15:42:32 -04:00
let path = dir.into();
2023-04-04 09:59:29 -04:00
let (s, r) = unbounded();
spawn(async move {
2023-05-29 15:42:32 -04:00
let cache = Cache::new(path).await;
cache.listen(r).await;
2023-04-04 09:59:29 -04:00
});
2023-05-29 15:42:32 -04:00
Ok(MoreThanText::new(s))
2023-04-04 09:59:29 -04:00
}