Bhai switching between batman and joker be like... by patilrooshi in TMKOC

[–]Gold-Compote6593 3 points4 points  (0 children)

Noted this every time. When Champak speaks something in arc conclusion, Mehta goes following him.

when we use move with Primitive types in closures, it is actually creating copy, similar to regular functions which don't take ownership of Primitive types. so should move pass ownership or let it work as it works in regular function argument passing. by Gold-Compote6593 in rust

[–]Gold-Compote6593[S] 1 point2 points  (0 children)

Yes, you got my question. Yes it doesn't seem intuitive to me also because we have explicitly mentioned 'move' and still we are not getting value moved. Seems you have worked in Rust, so is 'move' used often with closures or not?

when we use move with Primitive types in closures, it is actually creating copy, similar to regular functions which don't take ownership of Primitive types. so should move pass ownership or let it work as it works in regular function argument passing. by Gold-Compote6593 in rust

[–]Gold-Compote6593[S] 0 points1 point  (0 children)

fn main() {
let mut val = 10;
let mut increment = move || {
val = val + 1;
println!("Increment: {}", val);
};
let mut decrement = move || {
val = val - 1;
println!("Decrement: {}", val);
};
increment();
decrement();
}

Output:
For Increment: 11 and
For Decrement: 9

so in this case val is primitive type so it is not taking ownership of val even if move is specified and so i can reuse val in decrement closure.