I have the following situation:
let rpc_endpoint: String =
matches.value_of("rpc_endpoint").unwrap().to_owned();
/* later on... */
let create_order_route = warp::path!("book" / String)
.and(warp::post())
.and(warp::body::json())
.and(warp::any().map(move || create_order_state.clone()))
.and(warp::any().map(move || rpc_endpoint.as_str()))
.and_then(handler::create_order_handler);*/
The compiler complains about a potential lifetime issue:
error: lifetime may not live long enough
--> src/main.rs:153:38
|
153 | .and(warp::any().map(move || rpc_endpoint.as_str()))
| ------- ^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
| | |
| | return type of closure is &'2 str
| lifetime `'1` represents this closure's body
|
= note: closure implements `Fn`, so references to captured variables can't escape the closure
Is it not clear that rpc_endpoint.as_str()
will outlive the closure, as all references are Copy
?