面试题答案
一键面试struct Complex {
real: f64,
imag: f64,
}
impl std::ops::UnaryPlus for Complex {
type Output = Complex;
fn +(self) -> Complex {
let real = if self.real < 0.0 { 0.0 } else { self.real };
let imag = self.imag * 2.0;
Complex { real, imag }
}
}