I have the following code:
enum T {
A(bool),
B(u8),
}
fn main() {
let mut a = vec![T::A(true), T::B(42)];
match a[0] {
T::A(value) => println!("A: {}", value),
T::B(ref mut b) => {
match a[1] {
T::A(value) => println!("One more A: {}", value),
T::B(ref mut value) => *value += 1,
}
*b += 1
}
}
}
The compiler complains:
error[E0499]: cannot borrow `a` as mutable more than once at a time
--> src/main.rs:11:19
|
8 | match a[0] {
| - first mutable borrow occurs here
...
11 | match a[1] {
| ^ second mutable borrow occurs here
...
17 | }
| - first borrow ends here
I understand that the problem is because I have two mutable references to a
, but I cannot find the solution.