Adapted field type to use into()
This commit is contained in:
		@@ -1,16 +1,9 @@
 | 
				
			|||||||
use std::fmt;
 | 
					use std::fmt;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Clone, PartialEq)]
 | 
					 | 
				
			||||||
pub enum FieldType {
 | 
					pub enum FieldType {
 | 
				
			||||||
    StaticString(StaticString),
 | 
					    StaticString(StaticString),
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl FieldType {
 | 
					 | 
				
			||||||
    pub fn new(ftype: &str) -> FieldType {
 | 
					 | 
				
			||||||
        StaticString::new()
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
impl fmt::Display for FieldType {
 | 
					impl fmt::Display for FieldType {
 | 
				
			||||||
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 | 
					    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 | 
				
			||||||
        match self {
 | 
					        match self {
 | 
				
			||||||
@@ -19,16 +12,22 @@ impl fmt::Display for FieldType {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Clone, PartialEq)]
 | 
					impl From<StaticString> for FieldType {
 | 
				
			||||||
 | 
					    fn from(data: StaticString) -> Self {
 | 
				
			||||||
 | 
					        FieldType::StaticString(data)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub struct StaticString {
 | 
					pub struct StaticString {
 | 
				
			||||||
    data: String,
 | 
					    data: String,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl StaticString {
 | 
					impl StaticString {
 | 
				
			||||||
    pub fn new() -> FieldType {
 | 
					    pub fn new<S>(name: S) -> Self
 | 
				
			||||||
        FieldType::StaticString(Self {
 | 
					    where
 | 
				
			||||||
            data: "".to_string(),
 | 
					        S: Into<String>,
 | 
				
			||||||
        })
 | 
					    {
 | 
				
			||||||
 | 
					        Self { data: name.into() }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -38,27 +37,38 @@ impl fmt::Display for StaticString {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[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)]
 | 
					#[cfg(test)]
 | 
				
			||||||
mod staticstrings {
 | 
					mod staticstrings {
 | 
				
			||||||
    use super::*;
 | 
					    use super::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #[test]
 | 
					    #[test]
 | 
				
			||||||
    fn create_static_string() {
 | 
					    fn create_static_string() {
 | 
				
			||||||
        let field = StaticString::new();
 | 
					        let data = "some data";
 | 
				
			||||||
 | 
					        let field = StaticString::new(data);
 | 
				
			||||||
        assert!(
 | 
					        assert!(
 | 
				
			||||||
            field.to_string() == "",
 | 
					            field.to_string() == data,
 | 
				
			||||||
            "New should return an empty string."
 | 
					            "\n\nGot:  {}\nWant: {}",
 | 
				
			||||||
 | 
					            field.to_string(),
 | 
				
			||||||
 | 
					            data
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					        let ftype: FieldType = field.into();
 | 
				
			||||||
 | 
					        assert!(
 | 
				
			||||||
 | 
					            ftype.to_string() == data,
 | 
				
			||||||
 | 
					            "\n\nGot:  {}\nWant: {}",
 | 
				
			||||||
 | 
					            ftype.to_string(),
 | 
				
			||||||
 | 
					            data
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[test]
 | 
				
			||||||
 | 
					    fn accepts_string() {
 | 
				
			||||||
 | 
					        let data = "actual string";
 | 
				
			||||||
 | 
					        let field = StaticString::new(data.to_string());
 | 
				
			||||||
 | 
					        assert!(
 | 
				
			||||||
 | 
					            field.to_string() == data,
 | 
				
			||||||
 | 
					            "\n\nGot:  {}\nWant: {}",
 | 
				
			||||||
 | 
					            field.to_string(),
 | 
				
			||||||
 | 
					            data
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -164,6 +164,7 @@ impl Record {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /*
 | 
				
			||||||
    async fn update_field(&self, name: String, data: FieldType) {
 | 
					    async fn update_field(&self, name: String, data: FieldType) {
 | 
				
			||||||
        let mut map = self.data.write().await;
 | 
					        let mut map = self.data.write().await;
 | 
				
			||||||
        map.insert(name, data);
 | 
					        map.insert(name, data);
 | 
				
			||||||
@@ -176,6 +177,7 @@ impl Record {
 | 
				
			|||||||
            None => None,
 | 
					            None => None,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    */
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[cfg(test)]
 | 
					#[cfg(test)]
 | 
				
			||||||
@@ -235,6 +237,7 @@ mod tables {
 | 
				
			|||||||
mod records {
 | 
					mod records {
 | 
				
			||||||
    use super::*;
 | 
					    use super::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /*
 | 
				
			||||||
    #[async_std::test]
 | 
					    #[async_std::test]
 | 
				
			||||||
    async fn update_fields() {
 | 
					    async fn update_fields() {
 | 
				
			||||||
        let rec = Record::new();
 | 
					        let rec = Record::new();
 | 
				
			||||||
@@ -258,6 +261,7 @@ mod records {
 | 
				
			|||||||
        let output = rec.get_field(name).await;
 | 
					        let output = rec.get_field(name).await;
 | 
				
			||||||
        assert!(output == None, "Should return an option.");
 | 
					        assert!(output == None, "Should return an option.");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    */
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user