I have code that looks like this:
let contained_in_path = |n: usize| {
for p in paths.iter() {
for (i, x) in p.iter().enumerate() {
if x.0 == nit[n] {
return Some((i, p.clone()));
}
}
}
None
};
while next_i < nit.len()
&& (visited.contains(&nit[next_i]) || previous_path_ending(&paths, next_i))
{
next_i += 1;
if let Some((i, p)) = contained_in_path(next_i) {
...something mutating paths
}
}
}
Rust will of course complain, because the closure borrowed immutably, and now I'm trying to change it. Is there anyway to tell Rust that the first I call this closure is the only time I will call it? I.e. manually drop it before I try to mutate it again? A google search didn't turn up much that is helpful...