@@ -31,6 +31,9 @@ pub use self::buf_writer::BufWriter;
3131mod copy_into;
3232pub use self :: copy_into:: CopyInto ;
3333
34+ mod copy_buf_into;
35+ pub use self :: copy_buf_into:: CopyBufInto ;
36+
3437mod flush;
3538pub use self :: flush:: Flush ;
3639
@@ -441,6 +444,40 @@ impl<S: AsyncSeek + ?Sized> AsyncSeekExt for S {}
441444
442445/// An extension trait which adds utility methods to `AsyncBufRead` types.
443446pub trait AsyncBufReadExt : AsyncBufRead {
447+ /// Creates a future which copies all the bytes from one object to another.
448+ ///
449+ /// The returned future will copy all the bytes read from this `AsyncBufRead` into the
450+ /// `writer` specified. This future will only complete once the `reader` has hit
451+ /// EOF and all bytes have been written to and flushed from the `writer`
452+ /// provided.
453+ ///
454+ /// On success the number of bytes is returned.
455+ ///
456+ /// Note that this method consumes `writer` but does not close it, you will likely want to pass
457+ /// it by reference as shown in the example.
458+ ///
459+ /// # Examples
460+ ///
461+ /// ```
462+ /// #![feature(async_await)]
463+ /// # futures::executor::block_on(async {
464+ /// use futures::io::{AsyncBufReadExt, AsyncWriteExt};
465+ /// use std::io::Cursor;
466+ ///
467+ /// let reader = Cursor::new([1, 2, 3, 4]);
468+ /// let mut writer = Cursor::new([0u8; 5]);
469+ ///
470+ /// let bytes = reader.copy_buf_into(&mut writer).await?;
471+ /// writer.close().await?;
472+ ///
473+ /// assert_eq!(bytes, 4);
474+ /// assert_eq!(writer.into_inner(), [1, 2, 3, 4, 0]);
475+ /// # Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
476+ /// ```
477+ fn copy_buf_into < W : AsyncWrite > ( self , writer : W ) -> CopyBufInto < Self , W > where Self : Sized {
478+ CopyBufInto :: new ( self , writer)
479+ }
480+
444481 /// Creates a future which will read all the bytes associated with this I/O
445482 /// object into `buf` until the delimiter `byte` or EOF is reached.
446483 /// This method is the async equivalent to [`BufRead::read_until`](std::io::BufRead::read_until).
0 commit comments