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

Code before:
        }

        /// Flushes this output stream, ensuring that all intermediately buffered
        /// contents reach their destination.
        ///
        /// Equivalent to:
        ///
        /// ```ignore
        /// async fn flush(&mut self) -> io::Result<()>;
        /// ```
        ///
        /// # Errors
        ///
        /// It is considered an error if not all bytes could be written due to
        /// I/O errors or EOF being reached.
        ///
        /// # Cancel safety
        ///
        /// If `flush` is used as the event in a [`tokio::select!`](crate::select)
        /// statement and some other branch completes first, then the data in the
        /// buffered data in this `AsyncWrite` may have been partially flushed.
        /// However, it is guaranteed that the buffer is advanced by the amount
        /// of bytes that have been partially flushed.
        ///
        /// The same can be said in the case where the `flush` results in an error
        /// after polling the future to completion.
        ///
        /// # Examples
        ///
        /// ```no_run
        /// use tokio::io::{self, BufWriter, AsyncWriteExt};
        /// use tokio::fs::File;
        ///
        /// #[tokio::main]
        /// async fn main() -> io::Result<()> {
        ///     let f = File::create("foo.txt").await?;
        ///     let mut buffer = BufWriter::new(f);
        ///
        ///     buffer.write_all(b"some bytes").await?;
        ///     buffer.flush().await?;
        ///     Ok(())
        /// }
        /// ```
        fn flush(&mut self) -> Flush<'_, Self>
        where
            Self: Unpin,
        {
            flush(self)
        }

        /// Shuts down the output stream, ensuring that the value can be dropped

Review comment (refactor):
I don't think we can say anything about errors. If an error happens, the stream is probably in an invalid state. Probably just remove this.

Code after:
        }

        /// Flushes this output stream, ensuring that all intermediately buffered
        /// contents reach their destination.
        ///
        /// Equivalent to:
        ///
        /// ```ignore
        /// async fn flush(&mut self) -> io::Result<()>;
        /// ```
        ///
        /// # Errors
        ///
        /// It is considered an error if not all bytes could be written due to
        /// I/O errors or EOF being reached.
        ///
        /// # Cancel safety
        ///
        /// This method is cancel safe.
        ///
        /// If `flush` is used as the event in a [`tokio::select!`](crate::select)
        /// statement and some other branch completes first, then the data in the
        /// buffered data in this `AsyncWrite` may have been partially flushed.
        /// However, it is guaranteed that the buffer is advanced by the amount of
        /// bytes that have been partially flushed.
        ///
        /// # Examples
        ///
        /// ```no_run
        /// use tokio::io::{self, BufWriter, AsyncWriteExt};
        /// use tokio::fs::File;
        ///
        /// #[tokio::main]
        /// async fn main() -> io::Result<()> {
        ///     let f = File::create("foo.txt").await?;
        ///     let mut buffer = BufWriter::new(f);
        ///
        ///     buffer.write_all(b"some bytes").await?;
        ///     buffer.flush().await?;
        ///     Ok(())
        /// }
        /// ```
        fn flush(&mut self) -> Flush<'_, Self>
        where
            Self: Unpin,
        {
            flush(self)
        }

        /// Shuts down the output stream, ensuring that the value can be dropped
        /// cleanly.