pub fn websocket_handler_with_state<S, F, Fut>(
ws: WebSocketUpgrade,
state: S,
handler: F,
) -> ResponseExpand description
Helper to create a WebSocket handler with shared state.
ⓘ
async fn chat_socket(mut socket: WebSocket, state: AppState) {
// access state.db, state.config, etc.
}
Router::new()
.route("/ws/chat", get(|ws: WebSocketUpgrade, State(state): State<AppState>| {
websocket_handler_with_state(ws, state, chat_socket)
}))