Read from TlsStream<TcpStream> using `tokio-rustls`

I am using rustls, and want to read TlsStream to a buffer likewise we read TcpStream. Here is what I am doing:

let acceptor = TlsAcceptor::from(Arc::new(config));

let fut = async {

    let mut listener = TcpListener::bind(&addr).await?;

    loop {

        let (stream, peer_addr) = listener.accept().await?;
        let acceptor = acceptor.clone();

        let fut = async move {

            let mut stream = acceptor.accept(stream).await?;

            //// CURRENTLY THIS .read() is throwing error in compiler
            println!("Stream: {:?}", [0; 1024]));

            Ok(()) as io::Result<()>

        handle.spawn(fut.unwrap_or_else(|err| eprintln!("{:?}", err)));

It throws error

'error[E0599]: no method named read found for struct tokio_rustls::server::TlsStream<tokio::net::tcp::stream::TcpStream> in the current scope'

I am looking to read from TlsStream generated using tokio-rustls to buffer.

Have you imported Tokio's AsyncReadExt?

This is the dependencies in my cargo.toml

tokio = { version = "0.2", features = ["full"] }
futures-util = "0.3"
rustls = "0.17.0"
tokio-rustls = "0.13.0"

But have you imported it?

use tokio::io::AsyncReadExt;

Thanks alice. That was the error why it was not working due to the absent use statement.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.