为什么这一生不“过期”?

问题描述

对于随后的代码,生命周期'b'c何时结束?

use core::ops::Deref;

#[derive(Debug)]
struct A<'b,'c,T> {
    child_b: &'b T,child_c: &'c T
}

impl<'b,T> A<'b,T> {
    pub fn new_wrapper(b_value: &'b T,c_value: &'c T) -> A<'b,T> {
        A {
            child_b: b_value,child_c: c_value
        }
    }
}

fn doesnt_drop_borrow<T: Copy>(ty: &T) {
    *ty;
}

fn drop<T>(ty: T) { }

fn main() {
    let b: String = "wonderful".into();
    let c: String = "lifetime".into();
    let a = A::new_wrapper(&b,&c);
    println!("hello this {:?} world",&a);
    doesnt_drop_borrow(&a.child_c);
    drop(a.child_c);
    println!("hello this {:?} world",&a);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)