tokio: introduce I/O utility helpers

Created on 26 Jun 2019  路  5Comments  路  Source: tokio-rs/tokio

The existing I/O utility helpers were deleted in #1164. New ones should be implemented.

The utility helpers will be implemented on AsyncReadExt and AsyncWriteExt traits and will exist in tokio::io.

Some helpers to add include, but are not limited to:

AsyncReadExt

  • [x] read
  • [x] read_to_end
  • [x] read_to_string
  • [x] read_exact
  • [x] read_until
  • [x] copy

AsyncWriteExt

  • [x] write
  • [x] write_all
  • [x] flush

All 5 comments

I'm working on porting over read_until but it depends on the std::io::BufRead trait and the now deprecated try_nb! macro from tokio-io. I'm not sure how the BufRead bound will work with the new syntax.

One option is to copy over the functionality of read_until from BufRead into this future. This would mean adding a dependency on memchr though, as it looks like the standard library ships with its own version of the same.

Looks like read_to_end also depended on behavior from the Read trait and will have to be re-thought as well.

I think it is good to define the AsyncBufRead trait and experiment with it, like futures-io.

EDIT: Opened #1301

Does AsyncRead::split() belong on this list as well? It seems to have been replaced with a TCP-only implementation, but I was using it with UnixStream.

I am currently using futures 0.3's AsyncReadExt::split instead, via @Nemo157's shim from #1297, and it works beautifully.

@mokomull added a line item to #1256.

Was this page helpful?
0 / 5 - 0 ratings