string_ref_thread/
string_ref_thread.rs

1#[cfg(feature = "ok")]
2fn main() {
3    use std::sync::mpsc;
4    use std::thread;
5
6    let (tx, rx) = mpsc::channel();
7
8    thread::spawn(move || {
9        let instance = String::from("hi");
10        println!("Got from tx: {}", instance);
11
12        // the variable instance begin to move
13        tx.send(instance).unwrap();
14        // the variable instance moved here
15
16        // ERROR: The variable instance borrowed here after move
17        //println!("val is {}", &instance);
18    });
19
20    let received = rx.recv().unwrap();
21    println!("Got from rx: {}", received);
22}
23
24#[cfg(feature = "err")]
25fn main() {
26    use std::sync::mpsc;
27    use std::thread;
28
29    let (tx, rx) = mpsc::channel();
30
31    thread::spawn(move || {
32        let instance = String::from("hi");
33        println!("Got from tx: {}", instance);
34
35        // the variable instance begin to move
36        tx.send(&instance).unwrap();
37        // borrowed value does not live long enough argument
38        //      requires that instance is borrowed for 1
39        // the variable instance moved here
40
41        // ERROR: The variable instance borrowed here after move
42        // The variable instance dropped here while still borrowed
43        println!("val is {}", &instance);
44    });
45
46    let received = rx.recv().unwrap();
47    println!("Got from rx: {}", received);
48}
49
50#[cfg(all(not(feature = "ok"), not(feature = "err")))]
51fn main() {
52    use aide::hello;
53    hello();
54}
55
56// https://doc.rust-lang.org/stable/error-index.html#E0597