mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
412 B
26 lines
412 B
use std::ops::Add;
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq)]
|
|
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,
|
|
}
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
assert_eq!(
|
|
Point { x: 1, y: 0 } + Point { x: 2, y: 3 },
|
|
Point { x: 3, y: 3 }
|
|
);
|
|
}
|