Open Proteusiq opened 1 year ago
use std::fmt::{Display, Formatter, Result};
#[derive(Debug)]
struct Complex {
real: f32,
imag: f32,
}
impl Display for Complex {
fn fmt(&self, f: &mut Formatter) -> Result {
write!(f, "{real} + {imag}i", real=self.real, imag=self.imag)
}
}
fn main() {
let complex = Complex { real: 4.2, imag: 6.7 };
println!("equation:\n {}", complex);
println!("\n {:#?}", complex);
}