【发布时间】:2021-01-06 14:51:12
【问题描述】:
我在the official reference看到过这种代码:
trait Bar<'a>: 'a { }
我还没有想到这种情况。
我直观地解释一个类型的“生命周期”如下:
some_reference: &'a Some_Type = &instance_of_Some_Type;
T: 'a // T is borrowed by "instance_of_Some_Type"
trait Bar<'a>: 'a { } 是什么意思——有一个方法使用借用类型的参数?
和这个一样吗?
impl Bar<'a> for Another_Type
where
Another_Type: 'a
{
}
我想不出上述含义的用法,这种情况的示例用法是什么?我很难理解“特征的终身参数”的含义。
【问题讨论】:
标签: generics rust traits lifetime