blob: 83596ad87cb8189245aa7dac13f09c1ebb491f63 [file] [log] [blame]
// Structs, Borrowing
#![allow(dead_code)]
use rust_tutorial::*;
fn greet_person_1(p: Person) {
println!("Hello {} ({})!", p.name, p.age);
}
fn greet_person_2(p: &Person) {
println!("Hello {} ({})!", p.name, p.age);
}
fn birthday(p: &mut Person) {
p.age += 1;
}
fn main() {
// -- Struct instantiation --
let mut p = Person {
age: 30,
name: "Mary".to_string(),
};
// -- Borrowing --
//greet_person_1(p);
//greet_person_1(p);
greet_person_2(&p);
greet_person_2(&p);
birthday(&mut p);
greet_person_2(&p);
// -- Traits --
println!("p = {}", p.to_string());
// -- Debugging --
let x = dbg!(100 + 2) + 3;
println!("Hello, world! 100 + 2 + 3 = {}", x);
}