0

I need to mutably iterate over the Vec model.circles, so I get all permutations of two elements.

However, I can't get it to compile:

for ij in (0..model.circles.len()).permutations(2) {
    let i = ij[0];
    let j = ij[1];
    let circle = &mut model.circles[i];
    let other = &mut model.circles[j]; // cannot borrow `model.circles` as mutable more than once at a time

    // Mutating both elements
}

I get this error:

cannot borrow `model.circles` as mutable more than once at a time

How can I make this work?

mousetail
  • 7,009
  • 4
  • 25
  • 45
Antosser
  • 346
  • 1
  • 9

0 Answers0