Added Record to cachetype.
This commit is contained in:
parent
4914754f43
commit
58aba1a565
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
pub mod error;
|
||||
mod cachetype;
|
||||
pub mod error;
|
||||
|
||||
use async_std::{
|
||||
fs::{create_dir, read, remove_file, write},
|
||||
|
Loading…
Reference in New Issue
Block a user