morethantext-web/src/morethantext/fieldtype.rs

65 lines
1.2 KiB
Rust

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 {
FieldType::StaticString(data) => write!(f, "{}", data),
}
}
}
#[derive(Clone, PartialEq)]
pub struct StaticString {
data: String,
}
impl StaticString {
pub fn new() -> FieldType {
FieldType::StaticString(Self {
data: "".to_string(),
})
}
}
impl fmt::Display for StaticString {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", &self.data)
}
}
#[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();
assert!(
field.to_string() == "",
"New should return an empty string."
);
}
}