这样子也不行,牵扯到channel, 异至&vals有生命周期问题。
error[E0597]: `vals` does not live long enough
--> src/main.rs:15:20
|
6 | let (tx, rx) = mpsc::channel();
| -- lifetime `'1` appears in the type of `tx`
...
15 | for val in &vals {
| ^^^^^ borrowed value does not live long enough
16 | tx.send(val).unwrap();
| ------------ argument requires that `vals` is borrowed for `'1`
...
20 | });
| - `vals` dropped here while still borrowed
error: aborting due to previous error
For more information about this error, try `rustc --explain E0597`.
error: could not compile `test-vec`
就是要在 中间 !!
【 在 leadu 的大作中提到: 】
: 你想要的是不是这个
:
: for val in &vals { // vals moved,
: tx.send(val.clone()).unwrap();
: println!("Len in vec {:?}", vals.len()); // so invalide her
: ..................
发自「今日水木 on MRX-W29」
--
修改:txgx FROM 42.234.93.*
FROM 42.234.93.*