#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Complex { real: T, imag: T } impl Complex { fn new(real: T, imag: T) -> Complex { Complex{real: real, imag: imag} } } impl std::ops::Add for Complex where T: std::ops::Add + Copy { type Output = Complex; fn add(self, other: Self) -> Self { let real = self.real + other.real; let imag = self.imag + other.imag; Complex::new(real, imag) } } #[cfg(test)] mod tests { use super::*; #[test] fn addition() { let a = Complex::new(1, 5); let b = Complex::new(-3, 2); assert_eq!(a+b, Complex::new(-2, 7)); } }