51 lines
1014 B
Rust
51 lines
1014 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(data: &str) -> FieldType {
|
|
FieldType::StaticString(Self {
|
|
data: 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 data = "fred";
|
|
let field = StaticString::new(data);
|
|
assert!(
|
|
field.to_string() == data,
|
|
"\n\nGot: {}\nWant: {}\n\n",
|
|
field.to_string(),
|
|
data
|
|
);
|
|
}
|
|
}
|