I've been working on a web socket server and I am running into an odd error that I can't wrap my head around. I am using Warp web server and I have a ws handler like so:
pub async fn ws_handler(ws: warp::ws::Ws, chat_id: String, chat_manager: impl ChatManager, req_executor: Arc<impl RequestExecutor<String>>) -> Result<impl warp::Reply, Rejection> {
let chat = chat_manager.get_chat(&chat_id).await.map_err(|_| warp::reject::not_found())?;
Ok(ws.on_upgrade(move |socket| {
handle_websocket(socket, chat, req_executor)
}))
}
The error I am getting is:
error[E0310]: the parameter type `impl RequestExecutor<String>` may not live long enough
--> src/public_api/chat_websocket.rs:81:15
|
71 | pub async fn ws_handler(ws: warp::ws::Ws, chat_id: String, chat_manager: impl ChatManager, req_executor: Arc<impl RequestExecutor<String>>) -> Result<impl warp::Reply, Rejection> {
| ----------------------------------- help: consider adding an explicit lifetime bound...: `impl RequestExecutor<String> + 'static`
...
81 | Ok(ws.on_upgrade(move |socket| {
| ^^^^^^^^^^ ...so that the type `[closure@src/public_api/chat_websocket.rs:81:26: 83:10 chat:chat::Chat, executor:std::sync::Arc<impl RequestExecutor<String>>]` will meet its required lifetime bounds
I am particularly confused because I can pass the chat struct just fine, but not the req_executor. My understanding is that by using the move keyword, it should be taking ownership of the req_executor without issues. I have also tried calling clone() on the req_executor and calling clone right after the creation of the chat to make a cloned_req_executor. Neither of those make the error go away either