docs

v0.1.0 문서를 보고 있습니다. 이 버전은 더 이상 지원하지 않습니다. 최신 릴리스: v0.1.3 →

#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에서 이 페이지 고치기. 마지막 수정