Skip to main content

ws_handler

Function ws_handler 

Source
pub fn ws_handler<H>(handler: H) -> MethodRouter
where H: WsHandler,
Expand description

WsHandler 转为 axum MethodRouter,可直接注册到路由

返回 MethodRouter 而非裸 handler,避免 impl Fn 在 axum Handler trait 推导上的已知限制(impl Trait 返回类型无法被泛型 bound 正确解析)。

§用法

use sz_rust_router_facade::websocket_route::{ws_handler, EchoWsHandler};

let router = axum::Router::new()
    .route("/ws/echo", ws_handler(EchoWsHandler::new()));