From cff61e9a806ef1954d845ccdd25046ef3894109d Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Wed, 22 Jan 2020 21:17:30 +0800 Subject: [PATCH] add ops-test --- ops-test/Cargo.toml | 9 +++++++++ ops-test/src/main.rs | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 ops-test/Cargo.toml create mode 100644 ops-test/src/main.rs diff --git a/ops-test/Cargo.toml b/ops-test/Cargo.toml new file mode 100644 index 0000000..794eb22 --- /dev/null +++ b/ops-test/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "ops-test" +version = "0.1.0" +authors = ["Hatter Jiang "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/ops-test/src/main.rs b/ops-test/src/main.rs new file mode 100644 index 0000000..3edf04a --- /dev/null +++ b/ops-test/src/main.rs @@ -0,0 +1,25 @@ +#[derive(Debug, Clone)] +struct Point { + x: i32, + y: i32, +} + +impl std::ops::Add 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); +}