Created
November 18, 2018 20:01
-
-
Save rust-play/a14e281134718df6e4f0a62813c17b06 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::ops::Add; | |
struct Point<T> { | |
x: T, | |
y: T, | |
} | |
impl<T: Add> Add for Point<T> { | |
type Output = Point<T::Output>; | |
fn add(self, other: Point<T>) -> Self::Output { | |
Point { | |
x: self.x + other.x, | |
y: self.y + other.y, | |
} | |
} | |
} | |
fn main() { | |
let p1 = Point { x: 1, y: 0 }; | |
let p2 = Point { x: 2, y: 3 }; | |
let p3 = p1 + p2; | |
println!("Point: x = {}, y = {}", p3.x, p3.y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment