다음 코드를 사용하여 클로저 내에서 신호를 보내려고합니다.클로저에서 보내는 채널 신호
src/test.rs:8:19: 8:29 note: expected type `()`
src/test.rs:8:19: 8:29 note: found type `std::result::Result<(), std::sync::mpsc::SendError<std::string::String>>`
내가 뭔가를 놓치고 있습니까 :
use std::thread;
use std::sync::mpsc::channel;
fn main() {
let (tx, rx) = channel();
let t1 = thread::spawn(move || {
watch(|x| tx.send(x));
});
let t2 = thread::spawn(move || {
println!("{:?}", rx.recv().unwrap());
});
let _ = t1.join();
let _ = t2.join();
}
fn watch<F>(callback: F) where F : Fn(String) {
callback("hello world".to_string());
}
그러나, 다음과 같은 오류를 제기 컴파일 실패?