borrowing and references on Point
This commit is contained in:
parent
2a22cdcd51
commit
7402a7ec82
15 changed files with 8 additions and 4 deletions
12
src/main.rs
12
src/main.rs
|
@ -1,9 +1,13 @@
|
|||
#[derive(Clone, Debug)]
|
||||
#[derive(Debug)]
|
||||
struct Point(i32, i32);
|
||||
|
||||
fn add(p1: &Point, p2: &Point) -> Point {
|
||||
return Point(p1.0 + p2.0, p1.1 + p2.1);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let p1 = Point(3, 4);
|
||||
let p2 = p1.clone();
|
||||
println!("p1: {p1:?}");
|
||||
println!("p2: {p2:?}");
|
||||
let p2 = Point(10, 20);
|
||||
let p3 = add(&p1, &p2);
|
||||
println!("{p1:?} + {p2:?} = {p3:?}");
|
||||
}
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue