I struggle to understand why I can't call AsyncRead::poll_read()
on a ReadHalf
in tokio. Clearly AsyncRead
is implemented by ReadHalf
. AsyncRead
in turn requires the poll_read()
method. Still it does not seem to be visible. I guess it's somehow related to visibility exports in tokio, but I couldn't find a lead.
Here's an example (I'm using tokio 0.2.9)
use tokio::io::AsyncRead;
use tokio::io::Result;
use tokio::net::TcpListener;
use tokio::stream::StreamExt;
#[tokio::main]
async fn main() -> Result<()>{
let mut listener = TcpListener::bind("localhost:9187").await?;
let server = async move {
let mut incoming = listener.incoming();
while let Some(connection) = incoming.next().await {
if let Ok(mut tcp_stream) = connection {
tokio::spawn(async move {
let (reader, _writer) = tcp_stream.split();
let pn = reader.poll_read();
});
}
}
};
Ok(server.await)
}
The error message I get is:
error[E0599]: no method named `poll_read` found for type `tokio::net::tcp::split::ReadHalf<'_>` in the current scope
--> src/main.rs:16:37
|
16 | let pn = reader.poll_read();
| ^^^^^^^^^ method not found in `tokio::net::tcp::split::ReadHalf<'_>`
Why can't the AsyncRead::poll_read()
method be found?