From d09474bb14a0c764e080ae0c13b4e43607b0d70f Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Tue, 10 Jan 2023 10:12:44 -0500 Subject: [PATCH] Removed Record items for now. --- src/morethantext/cachetype.rs | 76 ----------------------------------- 1 file changed, 76 deletions(-) diff --git a/src/morethantext/cachetype.rs b/src/morethantext/cachetype.rs index 7240216..40bcefa 100644 --- a/src/morethantext/cachetype.rs +++ b/src/morethantext/cachetype.rs @@ -4,44 +4,12 @@ use std::{collections::HashMap, fmt, str}; #[derive(Clone)] pub enum CacheType { Raw(String), - Record(Record), -} - -#[derive(Clone)] -pub struct Record { - data: HashMap, -} - -impl Record { - fn new() -> Self { - Self { - data: HashMap::new(), - } - } - - fn add_field(&mut self, col: &str, data: &str) -> Result<(), DBError> { - match self.data.get(col) { - Some(_) => Err(DBError::new("duplicate field")), - None => { - self.data.insert(col.to_string(), data.to_string()); - Ok(()) - } - } - } - - fn get_field(&self, col: &str) -> Result { - match self.data.get(col) { - Some(item) => Ok(item.to_string()), - None => Err(DBError::new("missing field")), - } - } } impl CacheType { fn entry_type(&self) -> String { match self { CacheType::Raw(_) => "Raw".to_string(), - CacheType::Record(_) => "Record".to_string(), } } @@ -50,7 +18,6 @@ impl CacheType { output.push(0); match self { CacheType::Raw(s) => output.append(&mut s.as_bytes().to_vec()), - CacheType::Record(_) => todo!(), } return output; } @@ -73,7 +40,6 @@ impl fmt::Display for CacheType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { CacheType::Raw(s) => write!(f, "{}", s), - CacheType::Record(_) => todo!(), } } } @@ -111,46 +77,4 @@ mod enum_ctype { let holder = CacheType::Raw("nothing important".to_string()); assert_eq!(holder.entry_type(), "Raw"); } - - #[test] - fn get_record_type() { - let rec = Record::new(); - let holder = CacheType::Record(rec); - assert_eq!(holder.entry_type(), "Record"); - } -} - -#[cfg(test)] -mod record { - use super::*; - - #[test] - fn store() { - let data = "data"; - let mut rec = Record::new(); - rec.add_field("column", data).unwrap(); - let output = rec.get_field("column").unwrap(); - assert_eq!(output, data); - } - - #[test] - fn no_duplicate_fields() { - let mut rec = Record::new(); - rec.add_field("dup", "datai1").unwrap(); - match rec.add_field("dup", "datai2") { - Ok(_) => assert!(false, "Should have raised an error."), - Err(err) => { - assert_eq!(err.to_string(), "duplicate field"); - } - } - } - - #[test] - fn missing_field() { - let rec = Record::new(); - match rec.get_field("nothing") { - Ok(_) => assert!(false, "Should have errored."), - Err(err) => assert_eq!(err.to_string(), "missing field"), - } - } }