2022-02-06 16:43:51 +08:00
|
|
|
$ cargo check
|
|
|
|
Checking hello v0.1.0 (file:///projects/hello)
|
|
|
|
error[E0382]: use of moved value: `receiver`
|
2023-01-16 17:34:52 +08:00
|
|
|
--> src/lib.rs:26:42
|
2022-02-06 16:43:51 +08:00
|
|
|
|
|
2023-01-16 17:34:52 +08:00
|
|
|
21 | let (sender, receiver) = mpsc::channel();
|
2022-02-06 16:43:51 +08:00
|
|
|
| -------- move occurs because `receiver` has type `std::sync::mpsc::Receiver<Job>`, which does not implement the `Copy` trait
|
|
|
|
...
|
2024-06-06 21:23:21 +08:00
|
|
|
25 | for id in 0..size {
|
|
|
|
| ----------------- inside of this loop
|
2023-01-16 17:34:52 +08:00
|
|
|
26 | workers.push(Worker::new(id, receiver));
|
2022-02-06 16:43:51 +08:00
|
|
|
| ^^^^^^^^ value moved here, in previous iteration of loop
|
2024-06-06 21:23:21 +08:00
|
|
|
|
|
|
|
|
note: consider changing this parameter type in method `new` to borrow instead if owning the value isn't necessary
|
|
|
|
--> src/lib.rs:47:33
|
|
|
|
|
|
|
|
|
47 | fn new(id: usize, receiver: mpsc::Receiver<Job>) -> Worker {
|
|
|
|
| --- in this method ^^^^^^^^^^^^^^^^^^^ this parameter takes ownership of the value
|
2024-10-20 23:44:05 +08:00
|
|
|
help: consider moving the expression out of the loop so it is only moved once
|
|
|
|
|
|
|
|
|
25 ~ let mut value = Worker::new(id, receiver);
|
|
|
|
26 ~ for id in 0..size {
|
|
|
|
27 ~ workers.push(value);
|
|
|
|
|
|
2022-02-06 16:43:51 +08:00
|
|
|
|
|
|
|
For more information about this error, try `rustc --explain E0382`.
|
2024-06-06 21:23:21 +08:00
|
|
|
error: could not compile `hello` (lib) due to 1 previous error
|