Medium
std::ops::Add implemented for one struct but not the other
What happens when this program is compiled?
main.rs
use std::ops::Add;
#[derive(Debug, Clone, Copy)]
struct Point {
x: i32,
y: i32,
}
impl Add for Point {
type Output = Point;
fn add(self, other: Point) -> Point {
Point {
x: self.x + other.x,
y: self.y + other.y,
}
}
}
struct Meters(f64);
fn main() {
let a = Point { x: 1, y: 2 };
let b = Point { x: 3, y: 4 };
let c = a + b;
println!("{:?}", c);
let m1 = Meters(1.0);
let m2 = Meters(2.0);
let m3 = m1 + m2;
let _ = m3;
}21 of 53 in Rust