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

Code before:
///     mut bufs: &mut [IoSlice<'_>]
/// ) -> io::Result<()> {
///     while !bufs.is_empty() {
///         let n = write_vectored(writer, bufs).await?;
///         if n == 0 {
///             return Err(io::ErrorKind::WriteZero.into());
///         }
///         IoSlice::advance_slices(&mut bufs, n);
///     }
///     Ok(())
/// }
/// ```
///
/// # Cancel safety
///
/// This method is not cancellation safe. If it is used as the event
/// in a `tokio::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"))]
/// # {
/// use tokio_util::io::write_all_vectored;
/// use std::io::IoSlice;
///
/// #[tokio::main]
/// async fn main() -> std::io::Result<()> {
///
///     let mut writer = Vec::new();
///     let bufs = &mut [
///         IoSlice::new(&[1]),
///         IoSlice::new(&[2, 3]),
///         IoSlice::new(&[4, 5, 6]),
///     ];
///
///     write_all_vectored(&mut writer, bufs).await?;
///
///     // Note: `bufs` has been modified by `IoSlice::advance_slices` and should not be reused.
///     assert_eq!(writer, &[1, 2, 3, 4, 5, 6]);
///     Ok(())
/// }
/// # }
/// ```
///
/// # Notes
///
/// See the documentation for [`write_all_vectored`] from std.

Review comment (suggestion):
Instead of this block, can we do this?
```suggestion
/// # #![cfg(not(target_family = "wasm"))]
```
I'm pretty sure the block causes main to not actually be executed in the test suite.

Why is it disabled for wasm anyway? I don't think this uses threads. If it's due to the `#[tokio::main]` macro, you can use `#[tokio::main(flavor = "current_thread")]`

Code after:
///     mut bufs: &mut [IoSlice<'_>]
/// ) -> io::Result<()> {
///     while !bufs.is_empty() {
///         let n = write_vectored(writer, bufs).await?;
///         if n == 0 {
///             return Err(io::ErrorKind::WriteZero.into());
///         }
///         IoSlice::advance_slices(&mut bufs, n);
///     }
///     Ok(())
/// }
/// ```
///
/// # Cancel safety
///
/// This method is not cancellation safe. If it is used as the event
/// in a `tokio::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
/// use tokio_util::io::write_all_vectored;
/// use std::io::IoSlice;
///
/// #[tokio::main(flavor = "current_thread")]
/// async fn main() -> std::io::Result<()> {
///
///     let mut writer = Vec::new();
///     let bufs = &mut [
///         IoSlice::new(&[1]),
///         IoSlice::new(&[2, 3]),
///         IoSlice::new(&[4, 5, 6]),
///     ];
///
///     write_all_vectored(&mut writer, bufs).await?;
///
///     // Note: `bufs` has been modified by `IoSlice::advance_slices` and should not be reused.
///     assert_eq!(writer, &[1, 2, 3, 4, 5, 6]);
///     Ok(())
/// }
/// ```
///
/// # Notes
///
/// See the documentation for [`Write::write_all_vectored`] from std.
/// After calling this function, the buffer slices may have
/// been advanced and should not be reused.
///