chore: reorg
This commit is contained in:
6
__std/ops/Cargo.lock
generated
Normal file
6
__std/ops/Cargo.lock
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "ops-test"
|
||||
version = "0.1.0"
|
||||
|
||||
9
__std/ops/Cargo.toml
Normal file
9
__std/ops/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]
|
||||
64
__std/ops/src/main.rs
Normal file
64
__std/ops/src/main.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
#[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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Sub<Point> for Point {
|
||||
type Output = Self;
|
||||
|
||||
fn sub(self, rhs: Self) -> Self {
|
||||
Point {
|
||||
x: self.x - rhs.x,
|
||||
y: self.y - rhs.y,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Mul<Point> for Point {
|
||||
type Output = Self;
|
||||
|
||||
fn mul(self, rhs: Self) -> Self {
|
||||
Point {
|
||||
x: self.x * rhs.x,
|
||||
y: self.y * rhs.y,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Div<Point> for Point {
|
||||
type Output = Self;
|
||||
|
||||
fn div(self, rhs: Self) -> Self {
|
||||
Point {
|
||||
x: self.x / rhs.x,
|
||||
y: self.y / rhs.y,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a = Point { x: 2, y: 3, };
|
||||
let b = Point { x: 4, y: 5, };
|
||||
let c = a.clone() + b.clone();
|
||||
let d = a.clone() - b.clone();
|
||||
let e = a.clone() * b.clone();
|
||||
let f = a.clone() / b.clone();
|
||||
println!("{:?}", a);
|
||||
println!("{:?}", b);
|
||||
println!("{:?}", c);
|
||||
println!("{:?}", d);
|
||||
println!("{:?}", e);
|
||||
println!("{:?}", f);
|
||||
}
|
||||
Reference in New Issue
Block a user