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); +}