# Rust

# Clean up unnecessary crates

cargo install cargo-udeps --locked
rustup update
rustup update nightly
cargo +nightly udeps

# Install and update rust

Install rust

rustup update

# Tokio

// This code will work because tx_clone goes out of scope and tx goes out of scope after 5 sec.
#[tokio::main]
async fn main() {
    let (tx, mut rx) = tokio::sync::mpsc::channel(10);
    {
        let tx_clone = tx.clone();
        tokio::spawn(async move {
            std::thread::sleep(std::time::Duration::from_millis(5000));
            tx.send("hello".to_string()).await.unwrap();
        });
    }
    while let Some(txt) = rx.recv().await {
        println!("{}", &txt);
    }
    println!("finished");
}

In mpsc, the while loop for rx stops when all of the tx lifetime ends.

To get the inner value of Arc<Mutex<Foo>>:

let inner: Vec<_> = Arc::try_unwrap(foo).unwrap().into_inner();  

# Execution

cargo -cqx 'run -q'

keep running it quitely.

# Books