我正在尝试构建一个包含对另一个结构的向量的引用的结构,如下所示:
pub struct Downstream<'a> {
frequency: i32,
slot: i32,
connector: i32,
description: String,
cablemac: &'a CableMac,
}
pub struct Upstream<'a> {
downstreams: Vec<Downstream>,
}
无论我尝试什么,我总是会遇到这个生命周期错误:
src/e6000/mod.rs:13:22: 13:32 error: wrong number of lifetime parameters: expected 1, found 0 [E0107]
src/e6000/mod.rs:13 downstreams: Vec<Downstream>,
E0107 一点用都没有。
我在哪里以及如何放置一个 'a
来让它工作?
最佳答案
downstreams: Vec<Downstream>,
应该是
downstreams: Vec<Downstream<'a>>,
E0107 doesn't help at all.
您应该运行 rustc --explain E0107
。
该命令的输出当前以一些很好的示例开头:
This error means that an incorrect number of lifetime parameters were provided for a type (like a struct or enum) or trait.
Some basic examples include:
struct Foo<'a>(&'a str); enum Bar { A, B, C } struct Baz<'a> { foo: Foo, // error: expected 1, found 0 bar: Bar<'a>, // error: expected 0, found 1 }
关于rust - 在 Vec 中嵌套生命周期时,生命周期参数的数量错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37158911/