Added an Error create.
This commit is contained in:
		
							
								
								
									
										39
									
								
								src/morethantext/error.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								src/morethantext/error.rs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,39 @@
 | 
				
			|||||||
 | 
					use std::{error::Error, fmt};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[derive(Debug)]
 | 
				
			||||||
 | 
					pub struct MTTError {
 | 
				
			||||||
 | 
					    detail: String,
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl MTTError {
 | 
				
			||||||
 | 
					    fn new(detail: &str) -> Self {
 | 
				
			||||||
 | 
					        Self {
 | 
				
			||||||
 | 
					            detail: detail.to_string(),
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl fmt::Display for MTTError {
 | 
				
			||||||
 | 
					    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
 | 
				
			||||||
 | 
					        write!(f, "{}", self.detail)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Error for MTTError {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#[cfg(test)]
 | 
				
			||||||
 | 
					mod errors {
 | 
				
			||||||
 | 
					    use super::*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    #[test]
 | 
				
			||||||
 | 
					    fn new_error() {
 | 
				
			||||||
 | 
					        let detail = "new error";
 | 
				
			||||||
 | 
					        let err = MTTError::new(detail);
 | 
				
			||||||
 | 
					        assert!(
 | 
				
			||||||
 | 
					            err.to_string() == detail,
 | 
				
			||||||
 | 
					            "\n\nGot:  {}\nWant: {}\n\n",
 | 
				
			||||||
 | 
					            err.to_string(),
 | 
				
			||||||
 | 
					            detail
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -5,6 +5,12 @@ 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 {
 | 
				
			||||||
@@ -32,6 +38,17 @@ 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::*;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -98,8 +98,10 @@ impl Table {
 | 
				
			|||||||
use async_std::sync::{Arc, RwLock};
 | 
					use async_std::sync::{Arc, RwLock};
 | 
				
			||||||
use std::collections::HashMap;
 | 
					use std::collections::HashMap;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub mod error;
 | 
				
			||||||
mod fieldtype;
 | 
					mod fieldtype;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use error::MTTError;
 | 
				
			||||||
use fieldtype::{FieldType, StaticString};
 | 
					use fieldtype::{FieldType, StaticString};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Clone)]
 | 
					#[derive(Clone)]
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user