@@ -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
@@ -404,6 +407,36 @@ impl<S: AsyncSeek + ?Sized> AsyncSeekExt for S {}
404407
405408/// An extension trait which adds utility methods to `AsyncBufRead` types.
406409pub trait AsyncBufReadExt : AsyncBufRead {
410+ /// Creates a future which copies all the bytes from one object to another.
411+ ///
412+ /// The returned future will copy all the bytes read from this `AsyncBufRead` into the
413+ /// `writer` specified. This future will only complete once the `reader` has hit
414+ /// EOF and all bytes have been written to and flushed from the `writer`
415+ /// provided.
416+ ///
417+ /// On success the number of bytes is returned.
418+ ///
419+ /// # Examples
420+ ///
421+ /// ```
422+ /// #![feature(async_await)]
423+ /// # futures::executor::block_on(async {
424+ /// use futures::io::AsyncBufReadExt;
425+ /// use std::io::Cursor;
426+ ///
427+ /// let reader = Cursor::new([1, 2, 3, 4]);
428+ /// let mut writer = Cursor::new([0u8; 5]);
429+ ///
430+ /// let bytes = reader.copy_buf_into(&mut writer).await?;
431+ ///
432+ /// assert_eq!(bytes, 4);
433+ /// assert_eq!(writer.into_inner(), [1, 2, 3, 4, 0]);
434+ /// # Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
435+ /// ```
436+ fn copy_buf_into < W : AsyncWrite > ( self , writer : W ) -> CopyBufInto < Self , W > where Self : Sized {
437+ CopyBufInto :: new ( self , writer)
438+ }
439+
407440 /// Creates a future which will read all the bytes associated with this I/O
408441 /// object into `buf` until the delimiter `byte` or EOF is reached.
409442 /// This method is the async equivalent to [`BufRead::read_until`](std::io::BufRead::read_until).
0 commit comments