Struct Stdout

struct Stdout { ... }

A handle to the global standard output stream of the current process.

Each handle shares a global buffer of data to be written to the standard 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

When operating in a console, the Windows implementation of this stream does not support non-UTF-8 byte sequences. Attempting to write bytes that are not valid UTF-8 will return an error.

In a process with a detached console, such as one using #![windows_subsystem = "windows"], or in a child process spawned from such a process, 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.

Implementations

impl Stdout

fn lock(self: &Self) -> StdoutLock<'static>

Locks this handle to the standard output stream, returning a writable guard.

The lock is released when the returned lock goes out of scope. The returned guard also implements the Write trait for writing data.

Examples

use std::io::{self, Write};

fn main() -> io::Result<()> {
    let mut stdout = io::stdout().lock();

    stdout.write_all(b"hello world")?;

    Ok(())
}

impl AsFd for Stdout

fn as_fd(self: &Self) -> BorrowedFd<'_>

impl AsHandle for Stdout

fn as_handle(self: &Self) -> BorrowedHandle<'_>

impl AsRawFd for Stdout

fn as_raw_fd(self: &Self) -> RawFd

impl AsRawHandle for Stdout

fn as_raw_handle(self: &Self) -> RawHandle

impl Debug for Stdout

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl Freeze for Stdout

impl IsTerminal for Stdout

fn is_terminal(self: &Self) -> bool

impl RefUnwindSafe for Stdout

impl Send for Stdout

impl StdioExt for Stdout

fn set_fd<T: Into<OwnedFd>>(self: &mut Self, fd: T) -> Result<()>
fn take_fd(self: &mut Self) -> Result<OwnedFd>
fn replace_fd<T: Into<OwnedFd>>(self: &mut Self, replace_with: T) -> Result<OwnedFd>

impl Sync for Stdout

impl Unpin for Stdout

impl UnsafeUnpin for Stdout

impl UnwindSafe for Stdout

impl Write for Stdout

fn write(self: &mut Self, buf: &[u8]) -> Result<usize>
fn write_vectored(self: &mut Self, bufs: &[IoSlice<'_>]) -> Result<usize>
fn is_write_vectored(self: &Self) -> bool
fn flush(self: &mut Self) -> Result<()>
fn write_all(self: &mut Self, buf: &[u8]) -> Result<()>
fn write_all_vectored(self: &mut Self, bufs: &mut [IoSlice<'_>]) -> Result<()>
fn write_fmt(self: &mut Self, args: Arguments<'_>) -> Result<()>

impl<T> Any for Stdout

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Stdout

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Stdout

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> From for Stdout

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for Stdout

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom for Stdout

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for Stdout

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>