我尝试遵循strategy described in the book(和编译器),但遇到以下错误:
lifetime parameters are not allowed on this type: lifetime parameter not allowed
这是代码段:
struct FooRef<'a, F: 'a>(&'a F);
struct Bar<'a, 'f: 'a, F: Foo<'f>> {
filter: &'a FooRef<'f, F<'f>>,
}
答案 0 :(得分:2)
F
是类型变量,而不是类型,因此不能拥有自己的类型或生存期参数。如果您需要将类型变量限制为仅包含受生存期限制的引用,则可以将生存期用作绑定:
struct Bar<'a, 'f: 'a, F: Foo<'f> + 'f> {
filter: &'a FooRef<'f, F>,
}