Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions futures-util/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ pub use self::write_vectored::WriteVectored;
mod write_all;
pub use self::write_all::WriteAll;

#[cfg(feature = "write_all_vectored")]
#[cfg(feature = "write-all-vectored")]
mod write_all_vectored;
#[cfg(feature = "write_all_vectored")]
#[cfg(feature = "write-all-vectored")]
pub use self::write_all_vectored::WriteAllVectored;

/// An extension trait which adds utility methods to `AsyncRead` types.
Expand Down Expand Up @@ -493,22 +493,23 @@ pub trait AsyncWriteExt: AsyncWrite {
/// ```
/// # futures::executor::block_on(async {
/// use futures::io::AsyncWriteExt;
/// use std::io::{Cursor, IoSlice};
/// use futures_util::io::Cursor;
/// use std::io::IoSlice;
///
/// let mut writer = Cursor::new([0u8; 7]);
/// let mut writer = Cursor::new(Vec::new());
/// let bufs = &mut [
/// IoSlice::new(&[1]),
/// IoSlice::new(&[2, 3]),
/// IoSlice::new(&[4, 5, 6]),
/// ];
///
/// writer.write_all_vectored(bufs).await?;
/// // Note: the contents of `bufs` is now undefined, see the Notes section.
/// // Note: the contents of `bufs` is now unspecified, see the Notes section.
///
/// assert_eq!(writer.into_inner(), [1, 2, 3, 4, 5, 6, 0]);
/// assert_eq!(writer.into_inner(), &[1, 2, 3, 4, 5, 6]);
/// # Ok::<(), Box<dyn std::error::Error>>(()) }).unwrap();
/// ```
#[cfg(feature = "write_all_vectored")]
#[cfg(feature = "write-all-vectored")]
fn write_all_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSlice<'a>],
Expand Down
3 changes: 2 additions & 1 deletion futures-util/src/io/write_all_vectored.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl<W: ?Sized + Unpin> Unpin for WriteAllVectored<'_, W> {}

impl<'a, W: AsyncWrite + ?Sized + Unpin> WriteAllVectored<'a, W> {
pub(super) fn new(writer: &'a mut W, bufs: &'a mut [IoSlice<'a>]) -> Self {
WriteAllVectored { writer, bufs }
WriteAllVectored { writer, bufs: IoSlice::advance(bufs, 0) }
}
}

Expand Down Expand Up @@ -171,6 +171,7 @@ mod tests {
#[rustfmt::skip] // Becomes unreadable otherwise.
let tests: Vec<(_, &'static [u8])> = vec![
(vec![], &[]),
(vec![IoSlice::new(&[]), IoSlice::new(&[])], &[]),
(vec![IoSlice::new(&[1])], &[1]),
(vec![IoSlice::new(&[1, 2])], &[1, 2]),
(vec![IoSlice::new(&[1, 2, 3])], &[1, 2, 3]),
Expand Down