I\'m trying to implement something that looks like this minimal example:
trait Bar {}
struct Foo {
data: Vec>
asking me to consider adding a 'static lifetime qualifier (E0310). I am 99% sure that's not what I want, but I'm not exactly sure what I'm supposed to do.
Yes it is. The compiler does not want a &'static
reference, it wants U: 'static
.
Having U: 'static
means that U
contains no references with a lifetime less than 'static
. This is required because you want to put a U
instance in a structure without lifetimes.
trait Bar {}
struct Foo {
data: Vec>>,
}
impl Foo {
fn add + 'static>(&mut self, x: U) {
self.data.push(Box::new(x));
}
}