add error handling
This commit is contained in:
		
							parent
							
								
									5470a9b78a
								
							
						
					
					
						commit
						42773aa2a2
					
				| @ -9,7 +9,8 @@ pub type LJResult<T> = Result<T, Box<dyn std::error::Error>>; | ||||
| pub enum LJError { | ||||
|     Config(ConfigError), | ||||
|     RedisConnect(RedisError), | ||||
|     HeliosDeviceMissing | ||||
|     HeliosDeviceMissing, | ||||
|     BadEDH | ||||
| } | ||||
| 
 | ||||
| impl fmt::Display for LJError { | ||||
| @ -26,6 +27,9 @@ impl fmt::Display for LJError { | ||||
| 	    }, | ||||
| 	    HeliosDeviceMissing => { | ||||
| 		write!(f, "helios device not found") | ||||
| 	    }, | ||||
| 	    BadEDH => { | ||||
| 		write!(f, "EDH matrix is not a 3x3 matrix") | ||||
| 	    } | ||||
| 	} | ||||
|     } | ||||
|  | ||||
| @ -1,14 +1,20 @@ | ||||
| use crate::point::Color; | ||||
| use nalgebra::base::Matrix3; | ||||
| use crate::errors::LJResult; | ||||
| use crate::errors::{LJError,LJResult}; | ||||
| 
 | ||||
| #[derive(Debug, Default)] | ||||
| pub struct EDH { | ||||
| 	pub matrix: Matrix3<f32> | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| impl EDH { | ||||
|     pub fn new(vec: Vec<Vec<f32>>) -> LJResult<EDH> { | ||||
| 	if vec.len() != 3 || | ||||
| 	    vec[0].len() != 3 || | ||||
| 	    vec[1].len() != 3 || | ||||
| 	    vec[2].len() != 3 { | ||||
| 		return Err(Box::new(LJError::BadEDH)); | ||||
| 	    } | ||||
| 	let matrix = Matrix3::new(vec[0][0], vec[0][1], vec[0][2], | ||||
| 				  vec[1][0], vec[1][1], vec[1][2], | ||||
| 				  vec[2][0], vec[2][1], vec[2][2]); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user