doc-push icon indicating copy to clipboard operation
doc-push copied to clipboard

one-liner example for aync read

Open ultrasaurus opened this issue 4 years ago • 5 comments

Currently there is a TcpStream doc example of a one-liner that writes to a stream"

stream.write_all(b"hello world!").await?;

What would be an equivalent one-liner for read? (it could be read-N-bytes or read_until) I tried with read_lines, but it doesn't compile:

    stream.read_line(response).await?;

see full source, which fails with this error:

error[E0599]: no method named `read_line` found for type `tokio_net::tcp::stream::TcpStream` in the current scope
  --> src/main.rs:32:12
   |
32 |     stream.read_line(response).await?;
   |            ^^^^^^^^^
   |
   = note: the method `read_line` exists but the following trait bounds were not satisfied:
           `tokio_net::tcp::stream::TcpStream : tokio_io::io::async_buf_read_ext::AsyncBufReadExt`

How do I satisfy the trait bounds for AsyncBufReadExt? or is there a different / better approach?

ultrasaurus avatar Sep 25 '19 01:09 ultrasaurus