What is the right way to have multiple std::collections::LinkedList
s where the number of those lists is unknown at compile time?
I'm filling them with data as well as merging them (e.g. using append()
).
I thought it would be good to have a vector that contains those lists, or contains references to those lists.
I have tried the following:
use std::collections::LinkedList;
fn listtest() {
let mut v: Vec<LinkedList<i32>> = Vec::new();
v.push(LinkedList::new()); // first list
v.push(LinkedList::new()); // second list
v[0].push_back(1); // fill with data
v[1].push_back(3); // fill with data
v[0].append(&mut v[1]); // merge lists
}
fn main() {
listtest();
}
This fails to compile because I have two mutable references of v
when using append()
. I also tried using Vec<&mut LinkedList<i32>>
, but did not succeed.
What would be the right approach to this problem?