Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created November 18, 2018 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rust-play/a14e281134718df6e4f0a62813c17b06 to your computer and use it in GitHub Desktop.
Save rust-play/a14e281134718df6e4f0a62813c17b06 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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