1. impl<'a> Owner<'a> {
    2. fn get_resource(&self) -> Option<Box<dyn ResourceTrait<'a>>> {
    3. match &self.doc {
    4. Some(doc) => {
    5. Some(Box::new(TirdpartResource {
    6. data: doc.get_page()
    7. }))
    8. },
    9. None => Option::None
    10. }
    11. }
    12. }

    Box这种堆上内存的生命周期需要显式标注。
    方案1 让'_='a

    1. fn get_resource(&'a self) -> Option<Box<dyn ResourceTrait<'a> + 'a>>

    方案2 让'_ >= 'a:

    1. fn get_resource<'b: 'a>(&'b self) -> Option<Box<dyn ResourceTrait<'a> + 'b>>

    https://rustcc.cn/article?id=ae00e464-b11a-4b7a-88a8-d7fb4d1a9e37