From dd1aa38c0efabaa8690b67b1156abe621c1fe803 Mon Sep 17 00:00:00 2001 From: Jeff Baskin Date: Wed, 3 Aug 2022 08:23:00 -0400 Subject: [PATCH] moved field types into separate module. --- src/morethantext/fieldtype/mod.rs | 41 ++++++++++++++++++ .../static_string.rs} | 42 ++----------------- src/morethantext/mod.rs | 2 +- 3 files changed, 45 insertions(+), 40 deletions(-) create mode 100644 src/morethantext/fieldtype/mod.rs rename src/morethantext/{fieldtype.rs => fieldtype/static_string.rs} (51%) diff --git a/src/morethantext/fieldtype/mod.rs b/src/morethantext/fieldtype/mod.rs new file mode 100644 index 0000000..13d0662 --- /dev/null +++ b/src/morethantext/fieldtype/mod.rs @@ -0,0 +1,41 @@ +use std::fmt; + +mod static_string; + +use static_string::StaticString; + +pub enum FieldType { + StaticString(StaticString), +} + +impl fmt::Display for FieldType { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + FieldType::StaticString(data) => write!(f, "{}", data), + } + } +} + +impl From for FieldType { + fn from(data: StaticString) -> Self { + FieldType::StaticString(data) + } +} + +#[cfg(test)] +mod fieldtypes { + use super::*; + + #[test] + fn convert_static_string() { + let data = "a static string"; + let field = StaticString::new(data); + let ftype: FieldType = field.into(); + assert!( + ftype.to_string() == data, + "\n\nGot: {}\nWant: {}", + ftype.to_string(), + data + ); + } +} diff --git a/src/morethantext/fieldtype.rs b/src/morethantext/fieldtype/static_string.rs similarity index 51% rename from src/morethantext/fieldtype.rs rename to src/morethantext/fieldtype/static_string.rs index e47e7b9..f555990 100644 --- a/src/morethantext/fieldtype.rs +++ b/src/morethantext/fieldtype/static_string.rs @@ -1,23 +1,5 @@ use std::fmt; -pub enum FieldType { - StaticString(StaticString), -} - -impl fmt::Display for FieldType { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - FieldType::StaticString(data) => write!(f, "{}", data), - } - } -} - -impl From for FieldType { - fn from(data: StaticString) -> Self { - FieldType::StaticString(data) - } -} - pub struct StaticString { data: String, } @@ -38,29 +20,11 @@ impl fmt::Display for StaticString { } #[cfg(test)] -mod fieldtypes { +mod creation { use super::*; #[test] - fn convert_static_string() { - let data = "a static string"; - let field = StaticString::new(data); - let ftype: FieldType = field.into(); - assert!( - ftype.to_string() == data, - "\n\nGot: {}\nWant: {}", - ftype.to_string(), - data - ); - } -} - -#[cfg(test)] -mod staticstrings { - use super::*; - - #[test] - fn create_static_string() { + fn new_accepts_str() { let data = "some data"; let field = StaticString::new(data); assert!( @@ -72,7 +36,7 @@ mod staticstrings { } #[test] - fn accepts_string() { + fn new_accepts_string() { let data = "actual string"; let field = StaticString::new(data.to_string()); assert!( diff --git a/src/morethantext/mod.rs b/src/morethantext/mod.rs index 71ed011..67e4ae2 100644 --- a/src/morethantext/mod.rs +++ b/src/morethantext/mod.rs @@ -102,7 +102,7 @@ pub mod error; mod fieldtype; use error::MTTError; -use fieldtype::{FieldType, StaticString}; +use fieldtype::FieldType; #[derive(Clone)] pub struct MoreThanText;