The playground link Rust Playground contains two variants of a simple function.
The function is supposed to look up an element in a container. If the element doesn't exist, a new element should be added. In either case, a mutable reference to the element should be returned.
The first (commented out) variant is using a
for i in 0..self.children.len() loop and is working. The second variant is using a
for c in self.children.iter_mut() loop but is rejected by the borrow checker.
What would be an elegant way to make the second variant working?