> The compiler prefers to capture a closed-over variable by immutable borrow, followed by unique immutable borrow (see below), by mutable borrow, and finally by move. Composite types such as structs, tuples, and enums are always captured entirely, not by individual fields. It may be necessary to borrow into a local variable in order to capture a single field [...][1]
Definitely would prefer to avoid this type of concern though. Closures are neat for filters and terminating behaviors, but I've gotten bit by these rules before, myself. Definitely best to use the parameter arguments to be sure about what the closure is gonna receive. Can achieve OK semantics with
I guess this is kind of in the docs.
> The compiler prefers to capture a closed-over variable by immutable borrow, followed by unique immutable borrow (see below), by mutable borrow, and finally by move. Composite types such as structs, tuples, and enums are always captured entirely, not by individual fields. It may be necessary to borrow into a local variable in order to capture a single field [...][1]
Definitely would prefer to avoid this type of concern though. Closures are neat for filters and terminating behaviors, but I've gotten bit by these rules before, myself. Definitely best to use the parameter arguments to be sure about what the closure is gonna receive. Can achieve OK semantics with
and then [1] https://doc.rust-lang.org/1.80.1/reference/types/closure.htm...