Implement Display for Numbers

This commit is contained in:
Eryn Wells 2017-04-22 12:57:11 -07:00
parent a827958656
commit b5e9ce6ae2

View file

@ -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;