mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1.2 KiB
28 lines
1.2 KiB
3 years ago
|
$ cargo check
|
||
|
Checking hello v0.1.0 (file:///projects/hello)
|
||
|
error[E0382]: use of moved value: `receiver`
|
||
2 years ago
|
--> src/lib.rs:26:42
|
||
3 years ago
|
|
|
||
2 years ago
|
21 | let (sender, receiver) = mpsc::channel();
|
||
3 years ago
|
| -------- move occurs because `receiver` has type `std::sync::mpsc::Receiver<Job>`, which does not implement the `Copy` trait
|
||
|
...
|
||
6 months ago
|
25 | for id in 0..size {
|
||
|
| ----------------- inside of this loop
|
||
2 years ago
|
26 | workers.push(Worker::new(id, receiver));
|
||
3 years ago
|
| ^^^^^^^^ value moved here, in previous iteration of loop
|
||
6 months ago
|
|
|
||
|
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
|
||
1 month ago
|
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);
|
||
|
|
|
||
3 years ago
|
|
||
|
For more information about this error, try `rustc --explain E0382`.
|
||
6 months ago
|
error: could not compile `hello` (lib) due to 1 previous error
|