代码之家  ›  专栏  ›  技术社区  ›  Jacob Moreno

如何将tokio_tungstein::connect::connect_async()的结果存储为结构体的字段?

  •  0
  • Jacob Moreno  · 技术社区  · 1 年前

    我正在尝试构建一个处理异步websocket通信的结构体。我正在努力建立连接,作为其中的一部分,我正在使用 tokio_tungstenite::connect::connect_async() 。我想将其返回值作为字段存储在我正在处理的结构中。

    我尝试了以下方法:

    use tokio_tungstenite::tungstenite::stream::MaybeTlsStream;
    use tokio_tungstenite::WebSocketStream;
    
    pub struct WrAsyncSocket {
        m_socket_stream: Option<WebSocketStream<MaybeTlsStream<TcpStream>>>,
    }
    

    有了这个,我尝试了导入这两个:

    tokio::net::tcp::stream::TcpStream
    

    tokio::net::TcpStream
    

    但是,在任何实例上,这两种情况都会导致以下错误 TcpStream :

    the trait bound `tokio::net::TcpStream: std::io::Read` is not satisfied
    the trait `std::io::Read` is not implemented for `tokio::net::TcpStream`rustcClick for full compiler diagnostic
    stream.rs(63, 28): required by a bound in `tokio_tungstenite::tungstenite::stream::MaybeTlsStream`
    

    关于我在这里应该做什么,有什么建议吗?

    1 回复  |  直到 1 年前
        1
  •  0
  •   kmdreko    1 年前

    您可能想导入 tokio_tungstenite::MaybeTlsStream 相反。您正在使用的是从钨酸盐板条箱再出口的(不是 async )虽然这是 async 它的版本。