Skip to content

Commit

Permalink
Unrolled build for rust-lang#136798
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#136798 - pcorwin:master, r=tgross35

Added documentation for flushing per rust-lang#74348

Resolves rust-lang#74348
  • Loading branch information
rust-timer authored Mar 5, 2025
2 parents 4559163 + c392cf7 commit 758c50d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions library/std/src/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,11 @@ impl fmt::Debug for StdinLock<'_> {
/// output stream. Access is also synchronized via a lock and explicit control
/// over locking is available via the [`lock`] method.
///
/// By default, the handle is line-buffered when connected to a terminal, meaning
/// it flushes automatically when a newline (`\n`) is encountered. For immediate
/// output, you can manually call the [`flush`] method. When the handle goes out
/// of scope, the buffer is automatically flushed.
///
/// Created by the [`io::stdout`] method.
///
/// ### Note: Windows Portability Considerations
Expand All @@ -590,6 +595,7 @@ impl fmt::Debug for StdinLock<'_> {
/// standard library or via raw Windows API calls, will fail.
///
/// [`lock`]: Stdout::lock
/// [`flush`]: Write::flush
/// [`io::stdout`]: stdout
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Stdout {
Expand All @@ -604,6 +610,11 @@ pub struct Stdout {
/// This handle implements the [`Write`] trait, and is constructed via
/// the [`Stdout::lock`] method. See its documentation for more.
///
/// By default, the handle is line-buffered when connected to a terminal, meaning
/// it flushes automatically when a newline (`\n`) is encountered. For immediate
/// output, you can manually call the [`flush`] method. When the handle goes out
/// of scope, the buffer is automatically flushed.
///
/// ### Note: Windows Portability Considerations
///
/// When operating in a console, the Windows implementation of this stream does not support
Expand All @@ -615,6 +626,8 @@ pub struct Stdout {
/// the contained handle will be null. In such cases, the standard library's `Read` and
/// `Write` will do nothing and silently succeed. All other I/O operations, via the
/// standard library or via raw Windows API calls, will fail.
///
/// [`flush`]: Write::flush
#[must_use = "if unused stdout will immediately unlock"]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct StdoutLock<'a> {
Expand All @@ -629,6 +642,11 @@ static STDOUT: OnceLock<ReentrantLock<RefCell<LineWriter<StdoutRaw>>>> = OnceLoc
/// is synchronized via a mutex. If you need more explicit control over
/// locking, see the [`Stdout::lock`] method.
///
/// By default, the handle is line-buffered when connected to a terminal, meaning
/// it flushes automatically when a newline (`\n`) is encountered. For immediate
/// output, you can manually call the [`flush`] method. When the handle goes out
/// of scope, the buffer is automatically flushed.
///
/// ### Note: Windows Portability Considerations
///
/// When operating in a console, the Windows implementation of this stream does not support
Expand Down Expand Up @@ -669,6 +687,22 @@ static STDOUT: OnceLock<ReentrantLock<RefCell<LineWriter<StdoutRaw>>>> = OnceLoc
/// Ok(())
/// }
/// ```
///
/// Ensuring output is flushed immediately:
///
/// ```no_run
/// use std::io::{self, Write};
///
/// fn main() -> io::Result<()> {
/// let mut stdout = io::stdout();
/// stdout.write_all(b"hello, ")?;
/// stdout.flush()?; // Manual flush
/// stdout.write_all(b"world!\n")?; // Automatically flushed
/// Ok(())
/// }
/// ```
///
/// [`flush`]: Write::flush
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "io_stdout")]
Expand Down

0 comments on commit 758c50d

Please sign in to comment.