doc-push
doc-push copied to clipboard
one-liner example for aync read
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?