我有以下情况:
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);*/
编译器抱怨潜在的生命周期问题:
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
是否rpc_endpoint.as_str()
像所有参考文献一样,是否会比闭包更长寿Copy
?