Hello, I use the cassandra of the c/c++ driver to query, and then return the data.
Therefore, both cass (LinkedList) and cass_it (Vec) can show the result of the query.
However, I want to display the results to the web using the json format, so I chose to reassemble the data using vec. However, there is a problem:
error[E0434]: can't capture dynamic environment in a fn item
--> src/main.rs:306:42
|
306 | let out = serde_json::to_string(&cass_it).unwrap();
| ^^^^^^^
|
= help: use the `|| { ... }` closure form instead
What is wrong? format issue?
Code:
fn main() {
let mut cass = unsafe{cass_connect()};
let mut cass_it = Vec::new();
for cc in cass.iter() {
cass_it.push(cc);
}
println!("{:?}", cass_it);
let mut router = Router::new();
let localhost = "localhost:3009".to_string();
fn handler(req: &mut Request) -> IronResult<Response> {
// convert the response struct to JSON
let out = serde_json::to_string(&cass_it).unwrap();
let content_type = "application/json".parse::<Mime>().unwrap();
Ok(Response::with((content_type, status::Ok, out)))
}
router.get("/", handler, "index");
info!("Listening on {}", localhost);
Iron::new(router).http(localhost).unwrap();
}