#E0107: 移交了共用的值
這個值在其他程式碼仍能存取它的情況下(透過鎖、執行緒區域變數、Sync 物件,或同一個呼叫的另一個引數)被移交給另一個擁有者。請移交 .clone(),或一個沒有其他地方持有的值。
nabi
let m = Mutex::new([1, 2, 3]);
let (tx, rx) = channel::<List<i32>>();
using g = m.lock() {
try! tx.send(g.get());
}
error[E0107]: `g.get()` can't be sent through a channel: the `Mutex` behind `g` still holds it --> main.nabi:4:18 | 4 | try! tx.send(g.get()); | ^^^^^^^ | ------- taken out of the lock here | = help: hand over a deep copy (`g.get_clone()`), or take it out of the lock first (`g.set(..)` a new value)
送出複本:
nabi
let m = Mutex::new([1, 2, 3]);
let (tx, rx) = channel::<List<i32>>();
using g = m.lock() {
try! tx.send(g.get_clone());
}
println(f"{(rx.recv() ?? []).len()}");
3
相關錯誤碼:E0105 值在移交後被使用、E0106 值在其鎖釋放後被使用
發現錯誤? 在 GitHub 上編輯此頁 最後更新: