1. struct Person {
    2. name: String,
    3. age: u8,
    4. }
    5. fn main() {
    6. let p = Person {
    7. name: "Hao Chen".to_string(),
    8. age: 44,
    9. };
    10. //可以运行,因为 `u8` 有 Copy Trait
    11. let age = |p: &Person| p.age;
    12. // String 没有Copy Trait,所以,这里所有权就 Move 走了
    13. let name: for<'a> fn(&'a Person) -> &'a String = |p: &Person| &p.name;
    14. //下面的声明可以正确译
    15. // let name: for<'a> fn(&'a Person) -> &'a String = |p: &Person| &p.name;
    16. println!("name={}, age={}", name(&p), age(&p));
    17. }