Implement Display for Numbers
This commit is contained in:
		
							parent
							
								
									a827958656
								
							
						
					
					
						commit
						b5e9ce6ae2
					
				
					 1 changed files with 12 additions and 1 deletions
				
			
		|  | @ -6,8 +6,10 @@ | |||
| ///
 | ||||
| /// Scheme numbers are complex, literally.
 | ||||
| 
 | ||||
| use std::fmt; | ||||
| 
 | ||||
| pub mod real; | ||||
| //mod add;
 | ||||
| mod add; | ||||
| mod math; | ||||
| 
 | ||||
| pub use self::real::Real; | ||||
|  | @ -62,6 +64,15 @@ impl Number { | |||
|     pub fn is_exact(&self) -> bool { self.exact } | ||||
| } | ||||
| 
 | ||||
| impl fmt::Display for Number { | ||||
|     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||||
|         write!(f, "{}", self.real).and_then(|r| match self.imag { | ||||
|             Some(ref imag) => write!(f, "{}i", imag), | ||||
|             None => Ok(r), | ||||
|         }) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| #[cfg(test)] | ||||
| mod tests { | ||||
|     use super::Number; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue