rust - borrowed value must be valid for the static lifetime -


i can't piece of code work i'd read entries of hashmap in threads:

extern crate threadpool;  use threadpool::threadpool; use std::collections::hashmap; use std::sync::mpsc::{sender, receiver}; use std::sync::mpsc;  #[test] fn play() {     let mut rows = hashmap::new();     rows.insert(0u32, vec![1, 2, 3, 4]);     rows.insert(1u32, vec![5, 6]);      let pool = threadpool::new(2);      let (tx, rx): (sender<bool>, receiver<bool>) = mpsc::channel();      ref item in 0..2 {         let thread_tx = tx.clone();         let row = &rows[item];          pool.execute(move || { thread_tx.send(row.len() > 3); });     }      _ in 0..2 {         println!("{:?}", rx.recv());     } } 

the compiler gives me following exception:

error[e0597]: `rows` not live long enough   --> tests/play.rs:21:16    | 21 |     let row = &rows[item];    |                ^^^^ not live long enough ... 31 | }    | - borrowed value lives until here    |    = note: borrowed value must valid static lifetime... 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -