morethantext-web/src/morethantext/fieldtype.rs

48 lines
928 B
Rust

use std::fmt;
#[derive(Clone, PartialEq)]
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),
}
}
}
#[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 staticstrings {
use super::*;
#[test]
fn create_static_string() {
let field = StaticString::new();
assert!(
field.to_string() == "",
"New should return an empty string."
);
}
}