Matthias Benkard | 848739c | 2019-02-28 13:59:58 +0100 | [diff] [blame^] | 1 | // Structs, Borrowing |
2 | |||||
3 | #![allow(dead_code)] | ||||
4 | |||||
5 | use rust_tutorial::*; | ||||
6 | |||||
7 | fn greet_person(p: &Person) { | ||||
8 | println!("Hello {} ({})!", p.name, p.age); | ||||
9 | } | ||||
10 | |||||
11 | fn birthday(p: &mut Person) { | ||||
12 | p.age += 1; | ||||
13 | } | ||||
14 | |||||
15 | fn main() { | ||||
16 | // -- Struct instantiation -- | ||||
17 | let mut p = Person { | ||||
18 | age: 30, | ||||
19 | name: "Mary".to_string(), | ||||
20 | }; | ||||
21 | |||||
22 | greet_person(&p); | ||||
23 | greet_person(&p); | ||||
24 | |||||
25 | birthday(&mut p); | ||||
26 | |||||
27 | greet_person(&p); | ||||
28 | } |