2022-02-06 16:43:51 +08:00
|
|
|
$ cargo run
|
2023-01-16 17:34:52 +08:00
|
|
|
Compiling rectangles v0.1.0 (file:///projects/rectangles)
|
|
|
|
error[E0507]: cannot move out of `value`, a captured variable in an `FnMut` closure
|
|
|
|
--> src/main.rs:18:30
|
|
|
|
|
|
2024-06-06 21:23:21 +08:00
|
|
|
15 | let value = String::from("closure called");
|
2023-01-16 17:34:52 +08:00
|
|
|
| ----- captured outer variable
|
|
|
|
16 |
|
|
|
|
17 | list.sort_by_key(|r| {
|
|
|
|
| --- captured by this `FnMut` closure
|
|
|
|
18 | sort_operations.push(value);
|
|
|
|
| ^^^^^ move occurs because `value` has type `String`, which does not implement the `Copy` trait
|
2024-10-20 23:44:05 +08:00
|
|
|
|
|
|
|
|
help: consider cloning the value if the performance cost is acceptable
|
|
|
|
|
|
|
|
|
18 | sort_operations.push(value.clone());
|
|
|
|
| ++++++++
|
2022-02-06 16:43:51 +08:00
|
|
|
|
2023-01-16 17:34:52 +08:00
|
|
|
For more information about this error, try `rustc --explain E0507`.
|
2024-06-06 21:23:21 +08:00
|
|
|
error: could not compile `rectangles` (bin "rectangles") due to 1 previous error
|