Closed as duplicate of#107
Description
Code
fn main() {
let (sx, rx) = mpsc::channel();
let handle = thread::spawn(move |sx, rx| {
sx.send("hello").unwrap();
});
handle.join().unwrap();
}
It is recommended that threads support context. As shown in the figure, the context automatically performs cloning operations, which can avoid code, like this let handle = thread::spawn(move |sx, rx| {} not sx.clone(), rx.clone()。
This operation can be understood as opening an isolation domain. Or abstract it into a more general concept. Rust allows the creation of isolated domains. All external borrowing in the isolation domain is automatically recognized as a clone operation