I am already using a vec for it and it works, but I just wanted to see if I could allocate VLA's
On a side note, I want to remove a list of items from a larger list of items. Once one of the items to remove is found, it adds the index that way it doesn't have to search again for it (hence saving computation time, especially for large searches). Do you think the algorithm i have is optimal?
I'm definitely not the right person to answer. But I'll try anyway =) Based on the number of values in fields, you might gain some time by sorting it. If you want (need) to go even faster I'd try to use hashes.
A BitVec (or similar) might be faster than a Vec<bool>, you'd have to test but it'll be smaller at least.
But regardless I'd change:
let mut found_indexes = Vec::with_capacity(fields.len());
for _ in 0..found_indexes.capacity() {
(&mut found_indexes).push(false);
}
to:
let mut found_indexes = vec![false; fields.len()];
You should be able to use Iterator::zip instead of get_unchecked_mut.
And also do:
if !*found_index || line.field == entry.as_ref() {
This one is almost just formatting.
And if you copy/pasted all your code and only use fields once, you can remove:
let fields = fields.as_ref();
Just a note, you can use methods on found_indexes without taking a mutable reference to it.
In the end, most of my reply isn't really what you asked for (sorry) but it could be useful.