add ops-test
This commit is contained in:
9
ops-test/Cargo.toml
Normal file
9
ops-test/Cargo.toml
Normal 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
25
ops-test/src/main.rs
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user