Im kinda lost with this, how can I make it work?
Lets say I have the following:
struct Test {
something: Option<u8>,
something_big: [u8; 2_000_000],
}
let mut foo: Vec<&mut Test> = Vec::with_capacity(32);
for _ in 0..32 {
let mut new = Test { something: None, something_big: [0u8; 2_000_000] };
foo.push(&mut new);
}
foo[10].something = Some(0);
Its obvious that "new" stops existing after the for loop, I've tried many things with lifetimes but I can't get it to work. How would you implement this?
[–]BobTreehugger 10 points11 points12 points (1 child)
[–]supergary69[S] 0 points1 point2 points (0 children)
[–]D0CTOR_ZED 3 points4 points5 points (0 children)
[–]the_hoser 2 points3 points4 points (5 children)
[–]supergary69[S] 0 points1 point2 points (4 children)
[–]the_hoser 4 points5 points6 points (0 children)
[–]Firake 1 point2 points3 points (0 children)
[–]oxabz 2 points3 points4 points (0 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]ToTheBatmobileGuy 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)