let mut x = 13;
let y: &mut i32 = &mut x;
*y = *y + 1; // Expected to be this.
let mut fun = || { // Auto capture by `&mut x`.
x = x + 1; // Why not `*x = *x + 1;`?.
};
fun();
Is it getting automatically derefenced, just like in calling methods on references?
let mut count = 0;
// A closure to increment `count` could take either `&mut count` or `count`
// but `&mut count` is less restrictive so it takes that. Immediately
// borrows `count`.
let mut inc = || {
count += 1;
println!("`count`: {}", count);
};
I know count can be accessed directly inside the closure, but why &mut count and borrowing?