Repository: tokio-rs/tokio
File: tokio/src/io/util/async_write_ext.rs (Rust)

Code before:
        ///     file.write_vectored(&bufs).await?;
        ///     file.flush().await?;
        ///
        ///     Ok(())
        /// }
        /// # }
        /// ```
        ///
        /// [`write`]: AsyncWriteExt::write
        fn write_vectored<'a, 'b>(&'a mut self, bufs: &'a [IoSlice<'b>]) -> WriteVectored<'a, 'b, Self>
        where
            Self: Unpin,
        {
            write_vectored(self, bufs)
        }

        /// Like [`write_all`], except that it writes from a slice of buffers.
        ///
        /// Equivalent to:
        ///
        /// ```ignore
        /// async fn write_all_vectored(
        ///     &mut self,
        ///     bufs: &mut [IoSlice<'_>],
        /// ) -> io::Result<()> {
        ///     let mut pos = 0;
        ///     while !bufs.is_empty() {
        ///         let n = self.write_vectored(bufs).await?;
        ///         if n == 0 {
        ///             return Err(io::ErrorKind::WriteZero.into());
        ///         }
        ///         IoSlice::advance_slices(bufs, n);
        ///         pos += n;
        ///     }
        ///     Ok(())
        /// }
        /// ```
        ///
        /// # Cancel safety
        ///
        /// This method is not cancellation safe. If it is used as the event
        /// in a [`tokio::select!`](crate::select) statement and some other
        /// branch completes first, then the provided buffer may have been
        /// partially written, but future calls to `write_all_vectored` will
        /// have lost its place in the buffer.
        ///
        /// # Examples
        ///
        /// ```rust
        /// # #[cfg(not(target_family = "wasm"))]
        /// # {

Review comment (suggestion):
The `pos` variable is never used. Maybe return it as a result to make the example more complete ?!

Code after:
        ///     file.flush().await?;
        ///
        ///     Ok(())
        /// }
        /// # }
        /// ```
        ///
        /// [`write`]: AsyncWriteExt::write
        fn write_vectored<'a, 'b>(&'a mut self, bufs: &'a [IoSlice<'b>]) -> WriteVectored<'a, 'b, Self>
        where
            Self: Unpin,
        {
            write_vectored(self, bufs)
        }

        /// Writes a buffer into this writer, advancing the buffer's internal
        /// cursor.
        ///
        /// Equivalent to:
        ///
        /// ```ignore
        /// async fn write_buf<B: Buf>(&mut self, buf: &mut B) -> io::Result<usize>;
        /// ```
        ///
        /// This function will attempt to write the entire contents of `buf`, but
        /// the entire write may not succeed, or the write may also generate an
        /// error. After the operation completes, the buffer's
        /// internal cursor is advanced by the number of bytes written. A
        /// subsequent call to `write_buf` using the **same** `buf` value will
        /// resume from the point that the first call to `write_buf` completed.
        /// A call to `write_buf` represents *at most one* attempt to write to any
        /// wrapped object.
        ///
        /// # Return
        ///
        /// If the return value is `Ok(n)` then it must be guaranteed that `n <=
        /// buf.len()`. A return value of `0` typically means that the
        /// underlying object is no longer able to accept bytes and will likely
        /// not be able to in the future as well, or that the buffer provided is
        /// empty.
        ///
        /// # Errors
        ///
        /// Each call to `write` may generate an I/O error indicating that the
        /// operation could not be completed. If an error is returned then no bytes
        /// in the buffer were written to this writer.
        ///
        /// It is **not** considered an error if the entire buffer could not be
        /// written to this writer.
        ///
        /// # Cancel safety