diff --git a/src/morethantext/fieldtype.rs b/src/morethantext/fieldtype.rs index f39846b..07de4f3 100644 --- a/src/morethantext/fieldtype.rs +++ b/src/morethantext/fieldtype.rs @@ -1,16 +1,9 @@ use std::fmt; -#[derive(Clone, PartialEq)] pub enum FieldType { StaticString(StaticString), } -impl FieldType { - pub fn new(ftype: &str) -> FieldType { - StaticString::new() - } -} - impl fmt::Display for FieldType { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { @@ -19,16 +12,22 @@ impl fmt::Display for FieldType { } } -#[derive(Clone, PartialEq)] +impl From for FieldType { + fn from(data: StaticString) -> Self { + FieldType::StaticString(data) + } +} + pub struct StaticString { data: String, } impl StaticString { - pub fn new() -> FieldType { - FieldType::StaticString(Self { - data: "".to_string(), - }) + pub fn new(name: S) -> Self + where + S: Into, + { + Self { data: name.into() } } } @@ -38,27 +37,38 @@ impl fmt::Display for StaticString { } } -#[cfg(test)] -mod fieldtypes { - use super::*; - - #[test] - fn create_fieldtype() { - let ftype = FieldType::new("StaticString"); - assert!(ftype.to_string() == "", "Should return an empty string."); - } -} - #[cfg(test)] mod staticstrings { use super::*; #[test] fn create_static_string() { - let field = StaticString::new(); + let data = "some data"; + let field = StaticString::new(data); assert!( - field.to_string() == "", - "New should return an empty string." + field.to_string() == data, + "\n\nGot: {}\nWant: {}", + field.to_string(), + data + ); + let ftype: FieldType = field.into(); + assert!( + ftype.to_string() == data, + "\n\nGot: {}\nWant: {}", + ftype.to_string(), + data + ); + } + + #[test] + fn accepts_string() { + let data = "actual string"; + let field = StaticString::new(data.to_string()); + assert!( + field.to_string() == data, + "\n\nGot: {}\nWant: {}", + field.to_string(), + data ); } } diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index ce91f5d..71ed011 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -164,6 +164,7 @@ impl Record { } } + /* async fn update_field(&self, name: String, data: FieldType) { let mut map = self.data.write().await; map.insert(name, data); @@ -176,6 +177,7 @@ impl Record { None => None, } } + */ } #[cfg(test)] @@ -235,6 +237,7 @@ mod tables { mod records { use super::*; + /* #[async_std::test] async fn update_fields() { let rec = Record::new(); @@ -258,6 +261,7 @@ mod records { let output = rec.get_field(name).await; assert!(output == None, "Should return an option."); } + */ } /*