Files
Rust-High-Performance/Chapter03/example4.rs
2018-03-28 11:18:06 +05:30

27 lines
451 B
Rust

struct Parent<'p> {
age: u8,
child: Option<&'p Child>,
}
struct Child {
age: u8,
}
fn main() {
let child = Child { age: 10 };
let parent = Parent {
age: 35,
child: Some(&child),
};
println!("Child's age: {} years.", parent.child.unwrap().age);
}
fn oldest_child<'f>(child1: &'f Child, child2: &'f Child) -> &'f Child {
if child1.age > child2.age {
child1
} else {
child2
}
}