moved field types into separate module.
This commit is contained in:
		
							
								
								
									
										41
									
								
								src/morethantext/fieldtype/mod.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								src/morethantext/fieldtype/mod.rs
									
									
									
									
									
										Normal 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
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -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!(
 | 
			
		||||
@@ -102,7 +102,7 @@ pub mod error;
 | 
			
		||||
mod fieldtype;
 | 
			
		||||
 | 
			
		||||
use error::MTTError;
 | 
			
		||||
use fieldtype::{FieldType, StaticString};
 | 
			
		||||
use fieldtype::FieldType;
 | 
			
		||||
 | 
			
		||||
#[derive(Clone)]
 | 
			
		||||
pub struct MoreThanText;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user