this error:
                  
                  
                  error: borrowed data escapes outside of method
                  
                  
                  label: self is a reference that is only valid in the method body
                  
                  
                  
                  
                  
                      async fn start(&self) {
                  
                  
                          let users = Users::default();
                  
                  
                          let users = warp::any().map(move || users.clone());
                  
                  
                          let app = warp::path("ws")
                  
                  
                              // The `ws()` filter will prepare Websocket handshake...
                  
                  
                              .and(warp::ws())
                  
                  
                              .and(users)
                  
                  
                              .map(|ws: warp::ws::Ws, users| {
                  
                  
                                  return ws.on_upgrade(move |socket| self.clone().user_connected(socket, users));
                  
                  
                              });
                  
                  
                       }
                  
                  
                  
                  
                  
                  what can I do?
                  
                  
                
It would be nice if you attach the full error, and code If I had to take a guess, in the line: ws.on_upgrade(move |socket| self.clone().user_connected(socket, users)); you move &self into the closure, and only then clone it. you can do this instead: ws.on_upgrade({ let s = self.clone(); move |socket| self.clone().user_connected(socket, users) }); similarly, you don't need the clone at the second line
Обсуждают сегодня