mirror of
https://github.com/PacktPublishing/Rust-High-Performance.git
synced 2026-01-25 02:34:19 +09:00
27 lines
451 B
Rust
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
|
|
}
|
|
}
|