borrowing and references on Point

This commit is contained in:
Vincent Batts 2023-01-17 15:05:14 -05:00
parent 2a22cdcd51
commit 7402a7ec82
15 changed files with 8 additions and 4 deletions

View File

@ -1,9 +1,13 @@
#[derive(Clone, Debug)] #[derive(Debug)]
struct Point(i32, i32); struct Point(i32, i32);
fn add(p1: &Point, p2: &Point) -> Point {
return Point(p1.0 + p2.0, p1.1 + p2.1);
}
fn main() { fn main() {
let p1 = Point(3, 4); let p1 = Point(3, 4);
let p2 = p1.clone(); let p2 = Point(10, 20);
println!("p1: {p1:?}"); let p3 = add(&p1, &p2);
println!("p2: {p2:?}"); println!("{p1:?} + {p2:?} = {p3:?}");
} }

Binary file not shown.