struct Person {
name: String,
age: u8,
}
fn main() {
let p = Person {
name: "Hao Chen".to_string(),
age: 44,
};
//可以运行,因为 `u8` 有 Copy Trait
let age = |p: &Person| p.age;
// String 没有Copy Trait,所以,这里所有权就 Move 走了
let name: for<'a> fn(&'a Person) -> &'a String = |p: &Person| &p.name;
//下面的声明可以正确译
// let name: for<'a> fn(&'a Person) -> &'a String = |p: &Person| &p.name;
println!("name={}, age={}", name(&p), age(&p));
}