From 58aba1a565fe3d8a83202b9dd6ffb868c2fdbc59 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Sat, 31 Dec 2022 19:35:02 -0500 Subject: [PATCH] Added Record to cachetype. --- src/morethantext/cachetype.rs | 37 +++++++++++++++++++++++++++++------ src/morethantext/mod.rs | 2 +- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/morethantext/cachetype.rs b/src/morethantext/cachetype.rs index b7076c7..a0d7b0f 100644 --- a/src/morethantext/cachetype.rs +++ b/src/morethantext/cachetype.rs @@ -3,12 +3,23 @@ use std::{fmt, str}; #[derive(Clone)] pub enum CacheType { Raw(String), + Record(Record), +} + +#[derive(Clone)] +pub struct Record; + +impl Record { + fn new() -> Self { + Self {} + } } impl CacheType { fn entry_type(&self) -> String { match self { CacheType::Raw(_) => "Raw".to_string(), + CacheType::Record(_) => "Record".to_string(), } } @@ -17,6 +28,7 @@ impl CacheType { output.push(0); match self { CacheType::Raw(s) => output.append(&mut s.as_bytes().to_vec()), + CacheType::Record(_) => todo!(), } return output; } @@ -39,6 +51,7 @@ 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!(), } } } @@ -47,12 +60,6 @@ impl fmt::Display for CacheType { mod raw { use super::*; - #[test] - fn get_type() { - let holder = CacheType::Raw("nothing important".to_string()); - assert_eq!(holder.entry_type(), "Raw"); - } - #[test] fn get_bytes() { let data = "addams"; @@ -72,3 +79,21 @@ mod raw { assert_eq!(output.to_string(), holder.to_string()); } } + +#[cfg(test)] +mod enum_ctype { + use super::*; + + #[test] + fn get_raw_type() { + 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"); + } +} diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index e23a218..06fba46 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -1,5 +1,5 @@ -pub mod error; mod cachetype; +pub mod error; use async_std::{ fs::{create_dir, read, remove_file, write},