MCPcopy Create free account
hub / github.com/bedroombuilds/python2rust / main

Function main

22_websockets_server/rust/warp_ws/src/main.rs:19–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17
18#[tokio::main]
19async fn main() {
20 let users = Users::default();
21 let users = warp::any().map(move || users.clone());
22
23 let chat = warp::path("chat")
24 .and(warp::ws())
25 .and(users)
26 .map(|ws: warp::ws::Ws, users| {
27 ws.on_upgrade(move |socket| user_connected(socket, users))
28 });
29
30 let index = warp::path::end().map(|| warp::reply::html(INDEX_HTML));
31 let routes = index.or(chat);
32 warp::serve(routes).run(([127, 0, 0, 1], 8000)).await;
33}
34
35async fn user_connected(ws: WebSocket, users: Users) {
36 let my_id = NEXT_USER_ID.fetch_add(1, Ordering::Relaxed);

Callers

nothing calls this directly

Calls 1

user_connectedFunction · 0.85

Tested by

no test coverage detected