Reputation: 371
I'm trying to build a structure that contains references to a vector of another struct like this:
pub struct Downstream<'a> {
frequency: i32,
slot: i32,
connector: i32,
description: String,
cablemac: &'a CableMac,
}
pub struct Upstream<'a> {
downstreams: Vec<Downstream>,
}
Whatever I try, I always get this lifetime error:
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 doesn't help at all.
Where and how so I put an 'a
to get this working?
Upvotes: 1
Views: 805
Reputation: 222328
downstreams: Vec<Downstream>,
should be
downstreams: Vec<Downstream<'a>>,
E0107 doesn't help at all.
You should run rustc --explain E0107
.
The output of that command currently starts with some nice examples:
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 }
Upvotes: 3