// main.rs
#[derive(Clone, Copy)]
struct A(f64, f64);
impl<T> Mul<T> for A
where
f64: From<T>,
T: Copy, // f64: Mul<T>,
{
type Output = A;
fn mul(mut self, rhs: T) -> Self::Output {
self.0 = self.0 * f64::from(rhs);
self.1 = self.1 * f64::from(rhs);
self
}
}
impl Mul<A> for i32 {
type Output = A;
fn mul(self, mut rhs: A) -> Self::Output {
rhs.0 = rhs.0 * f64::from(self);
rhs.1 = rhs.1 * f64::from(self);
rhs
}
}
fn main() {
let mut …Run Code Online (Sandbox Code Playgroud)