Похожие чаты

Hello I try to implement websocket server using warp and I get

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?

1 ответов

13 просмотров

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

Похожие вопросы

Обсуждают сегодня

А еще в перле можно уже @arr1 + @arr2?
Sergei Zhmylove
53
я не магистр хаскеля, но разве не может лейзи тип конвертнуться в не-лейзи запросив вычисление содержимого прям при инициализации?
deadgnom32 λ madao
100
I arrived here after a Chico Crypto show highlighted the project & the Team - the fact that the Team had a long history of successfully working with household names gave me e...
Banter is Bullish
1
Привет всем. появился вопрос. Разрабатываю сайт, в данный момент он запущен. Хостинг beget. Добавляю на сайт яндекс метрику с помощью полей client-settings (взято отсюда http...
Andrew
2
Подскажите, где смотреть результат выполнения программы? Код: ;.686 ;Система команд процессора 686 ;.MODEL FLAT,stdcall ;Модель памяти плоская, станда...
Егор Анелькин
5
Где в Астане можно купить мясо для шашлыков?
Dancing Іңұқәһүғө
21
Lers say somehow tor got shut down What then?
Mark Keller
16
Добрый день подскажите пожалуйста может кто то сталкивался с ошибками Sentry 22.10.0 развернутым из helm чарт в Kubernetes? Изначально 3 дня назад очень стало много событий ух...
Tire4 Finist Devops
1
Ну чё, сегодня все в гавно?))
ᅠ🚀
20
;.686 ;Система команд процессора 686 ;.MODEL FLAT,stdcall ;Модель памяти плоская, стандартный ;вызов процедуры ;option casemap:no...
Егор Анелькин
1
Карта сайта