add ops-test

This commit is contained in:
2020-01-22 21:17:30 +08:00
parent febcd6349a
commit cff61e9a80
2 changed files with 34 additions and 0 deletions

9
ops-test/Cargo.toml Normal file
View File

@@ -0,0 +1,9 @@
[package]
name = "ops-test"
version = "0.1.0"
authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

25
ops-test/src/main.rs Normal file
View File

@@ -0,0 +1,25 @@
#[derive(Debug, Clone)]
struct Point {
x: i32,
y: i32,
}
impl std::ops::Add<Point> for Point {
type Output = Self;
fn add(self, rhs: Self) -> Self {
Point {
x: self.x + rhs.x,
y: self.y + rhs.y,
}
}
}
fn main() {
let a = Point { x: 1, y: 2, };
let b = Point { x: 2, y: 4, };
let c = a.clone() + b;
println!("{:?}", a);
// println!("{:?}", b);
println!("{:?}", c);
}