I'm trying to build a struct that handles async websocket communication. I'm working on getting the connection set up and, as part of that, I'm using tokio_tungstenite::connect::connect_async()
. I want to store its returned value as a field in the struct I'm working on.
I've tried the following:
use tokio_tungstenite::tungstenite::stream::MaybeTlsStream;
use tokio_tungstenite::WebSocketStream;
pub struct WrAsyncSocket {
m_socket_stream: Option<WebSocketStream<MaybeTlsStream<TcpStream>>>,
}
With this, I've tried importing both:
tokio::net::tcp::stream::TcpStream
and
tokio::net::TcpStream
However, both result in the following error on any instance of 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`
Any advice on what I should be doing here?
You likely want to import tokio_tungstenite::MaybeTlsStream
instead. The one you are using is a re-export from the tungstenite crate (which is not async
) while this is the async
version of it.