Skip to content

Commit

Permalink
add details to docs of tokio::io::copy[_buf]
Browse files Browse the repository at this point in the history
regarding extra buffer allocation and the differences between the two
functions
  • Loading branch information
marcospb19 committed Mar 22, 2023
1 parent a7bb054 commit 9fb88e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion tokio/src/io/util/copy.rs
Expand Up @@ -153,14 +153,20 @@ cfg_io_util! {
///
/// This function returns a future that will continuously read data from
/// `reader` and then write it into `writer` in a streaming fashion until
/// `reader` returns EOF.
/// `reader` returns EOF or fails.
///
/// On success, the total number of bytes that were copied from `reader` to
/// `writer` is returned.
///
/// This is an asynchronous version of [`std::io::copy`][std].
///
/// A heap-allocated buffer with 8 KB is created to take data from the
/// reader to the writer, check [`copy_buf`] if you want an alternative
/// for [`AsyncBufRead`].
///
/// [std]: std::io::copy
/// [`copy_buf`]: crate::io::copy_buf
/// [`AsyncBufRead`]: crate::io::AsyncBufRead
///
/// # Errors
///
Expand Down
8 changes: 7 additions & 1 deletion tokio/src/io/util/copy_buf.rs
Expand Up @@ -24,11 +24,17 @@ cfg_io_util! {
///
/// This function returns a future that will continuously read data from
/// `reader` and then write it into `writer` in a streaming fashion until
/// `reader` returns EOF.
/// `reader` returns EOF or fails.
///
/// On success, the total number of bytes that were copied from `reader` to
/// `writer` is returned.
///
/// This is a [`tokio::io::copy`] alternative for [`AsyncBufRead`] readers,
/// with no extra buffer allocation, since [`AsyncBufRead`] allow access
/// to the reader's inner buffer.
///
/// [`tokio::io::copy`]: crate::io::copy
/// [`AsyncBufRead`]: crate::io::AsyncBufRead
///
/// # Errors
///
Expand Down

0 comments on commit 9fb88e3

Please sign in to comment.