'Why won't the reference to self get dropped
Consider the following programm. Why isn't the reference to self dropped after the first call to foo and how can I resolve this issue without changing the mutability of the foo function parameters.
struct MyElement<'a>(&'a u32);
struct MyStruct(u32);
impl MyStruct {
fn foo<'a>(&'a mut self, vec: &mut Vec<MyElement<'a>>) {
vec.push(MyElement(&self.0));
}
}
fn main() {
let mut mystruct = MyStruct(42);
let mut vec = Vec::new();
mystruct.foo(&mut vec);
mystruct.foo(&mut vec);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
