From 77c0f9f18953717e846db62c088a673cf9040c5f Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Thu, 2 Feb 2023 21:55:18 -0500 Subject: [PATCH] Removed session so it is part of the database. --- src/morethantext/mod.rs | 14 +++------ src/morethantext/session.rs | 62 ------------------------------------- 2 files changed, 4 insertions(+), 72 deletions(-) delete mode 100644 src/morethantext/session.rs diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index 80c9ffa..1bf1fa2 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -1,6 +1,5 @@ mod databases; pub mod error; -mod session; use async_std::{ fs::{create_dir, read, remove_file, write}, @@ -11,7 +10,6 @@ use async_std::{ use databases::Databases; use error::DBError; use rand::{distributions::Alphanumeric, thread_rng, Rng}; -use session::Session; use std::{ collections::HashMap, fmt, slice, str, @@ -132,7 +130,7 @@ impl fmt::Display for CacheEntry { pub struct MoreThanText { cache: Arc>>, dir: String, - session: Session, + session: Vec, } impl MoreThanText { @@ -151,7 +149,7 @@ impl MoreThanText { let mut output = Self { cache: Arc::new(Mutex::new(HashMap::new())), dir: data_dir.to_str().unwrap().to_string(), - session: Session::new(), + session: Vec::new(), }; let entry_file = Path::new(dir).join(ENTRY); let id: String; @@ -343,7 +341,7 @@ mod init { let id = str::from_utf8(&data).unwrap(); let cache = db.get_entry(&id).await.unwrap(); assert_eq!(cache.data.entry_type(), "DBMap"); - assert_eq!(db.session.get_data(), [id]); + assert_eq!(db.session, [id]); } #[async_std::test] @@ -355,11 +353,7 @@ mod init { let db2 = MoreThanText::new(dir.path().to_str().unwrap()) .await .unwrap(); - assert_eq!( - db1.session.get_data(), - db2.session.get_data(), - "Did not read existing entry." - ); + assert_eq!(db1.session, db2.session, "Did not read existing entry."); } } diff --git a/src/morethantext/session.rs b/src/morethantext/session.rs deleted file mode 100644 index 037b13a..0000000 --- a/src/morethantext/session.rs +++ /dev/null @@ -1,62 +0,0 @@ -#[derive(Clone)] -pub struct Session { - data: Vec, - error: Option, -} - -impl Session { - pub fn new() -> Self { - Self { - data: Vec::new(), - error: None, - } - } - - pub fn push(&mut self, id: String) { - self.data.push(id); - } - - pub fn append(&mut self, mut data: Vec) { - self.data.append(&mut data); - } - - pub fn get_data(&self) -> Vec { - self.data.clone() - } -} - -#[cfg(test)] -mod setup { - use super::*; - - #[test] - fn add_item() { - let mut sess = Session::new(); - let id = "frog".to_string(); - sess.push(id.clone()); - assert!(sess.data.contains(&id), "{} not in {:?}", id, sess.data); - } - - #[test] - fn add_list() { - let mut sess = Session::new(); - let mut data: Vec = Vec::new(); - data.push("fred".to_string()); - data.push("barney".to_string()); - sess.append(data.clone()); - assert_eq!(sess.data, data); - } -} - -#[cfg(test)] -mod data { - use super::*; - - #[test] - fn show_data() { - let data = ["pne".to_string(), "two".to_string(), "three".to_string()]; - let mut sess = Session::new(); - sess.append(data.to_vec()); - assert_eq!(sess.get_data(), data); - } -}