moved field types into separate module.

This commit is contained in:
Jeff Baskin 2022-08-03 08:23:00 -04:00
parent fc91e2cd8b
commit dd1aa38c0e
3 changed files with 45 additions and 40 deletions

View File

@ -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<StaticString> 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
);
}
}

View File

@ -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<StaticString> 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!(

View File

@ -102,7 +102,7 @@ pub mod error;
mod fieldtype;
use error::MTTError;
use fieldtype::{FieldType, StaticString};
use fieldtype::FieldType;
#[derive(Clone)]
pub struct MoreThanText;