0
use futures_util::{FutureExt, StreamExt};
use warp::{Filter, filters::BoxedFilter, Reply};

// websocket echo
pub fn websocket_filter() -> BoxedFilter<(impl Reply, )> {
    return warp::path!("echo")
        .and(warp::ws())
        .map(|ws: warp::ws::Ws| {
            ws.on_upgrade(|websocket| {
                // Just echo all messages back...
                let (tx, rx) = websocket.split();
                rx.forward(tx).map(|result| {
                    if let Err(e) = result {
                        eprintln!("websocket error: {:?}", e);
                    }
                })
            });

            "end"
        }).boxed();
}

使用上面的代码,Idea 显示错误消息“不匹配的类型 [E0308] 预期BoxedFilter<(impl Reply,)>,找到BoxFuture<&str>”。但它建立了成功。

4

0 回答 0