On this page
Struct std::io::Stdout
pub struct Stdout { /* private fields */ }
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.
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
pub fn lock(&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(())
}
Trait Implementations
impl AsFd for Stdout
impl AsHandle for StdoutAvailable on Windows only.
impl AsRawFd for Stdout
impl AsRawHandle for StdoutAvailable on Windows only.
impl Debug for Stdout
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl From<Stdout> for Stdio
fn from(inherit: Stdout) -> Stdio
Redirect command stdout/stderr to our stdout
Examples
#![feature(exit_status_error)]
use std::io;
use std::process::Command;
let output = Command::new("whoami")
.stdout(io::stdout())
.output()?;
output.status.exit_ok()?;
assert!(output.stdout.is_empty());
impl IsTerminal for Stdout
fn is_terminal(&self) -> bool
true
if the descriptor/handle refers to a terminal/tty. Read more
impl Write for &Stdout
fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize>
fn is_write_vectored(&self) -> bool
can_vector
#69941)
fn flush(&mut self) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<()>
write_all_vectored
#70436)
fn write_fmt(&mut self, args: Arguments<'_>) -> Result<()>
fn by_ref(&mut self) -> &mut Self
where
Self: Sized,
Write
. Read more
impl Write for Stdout
fn write(&mut self, buf: &[u8]) -> Result<usize>
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize>
fn is_write_vectored(&self) -> bool
can_vector
#69941)
fn flush(&mut self) -> Result<()>
fn write_all(&mut self, buf: &[u8]) -> Result<()>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<()>
write_all_vectored
#70436)
fn write_fmt(&mut self, args: Arguments<'_>) -> Result<()>
fn by_ref(&mut self) -> &mut Self
where
Self: Sized,
Write
. Read more
Auto Trait Implementations
impl RefUnwindSafe for Stdout
impl Send for Stdout
impl Sync for Stdout
impl Unpin for Stdout
impl UnwindSafe for Stdout
Blanket Implementations
impl<T> Any for T
where
T: 'static + ?Sized,
impl<T> Borrow<T> for T
where
T: ?Sized,
impl<T> BorrowMut<T> for T
where
T: ?Sized,
impl<T> From<T> for T
fn from(t: T) -> T
Returns the argument unchanged.
impl<T, U> Into<U> for T
where
U: From<T>,
fn into(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<U> for T
where
U: Into<T>,
type Error = Infallible
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto<U> for T
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/io/struct.Stdout.html