Struct Stdout

struct Stdout { ... }

A handle to the standard output stream of a process.

Concurrent writes to stdout must be executed with care: Only individual writes to this AsyncWrite are guaranteed to be intact. In particular you should be aware that writes using write_all are not guaranteed to occur as a single write, so multiple threads writing data with write_all may result in interleaved output.

Created by the stdout function.

Examples

use tokio::io::{self, AsyncWriteExt};

#[tokio::main]
async fn main() -> io::Result<()> {
    let mut stdout = io::stdout();
    stdout.write_all(b"Hello world!").await?;
    Ok(())
}

The following is an example of using stdio with loop.

use tokio::io::{self, AsyncWriteExt};

#[tokio::main]
async fn main() {
    let messages = vec!["hello", " world\n"];

    // When you use `stdio` in a loop, it is recommended to create
    // a single `stdio` instance outside the loop and call a write
    // operation against that instance on each loop.
    //
    // Repeatedly creating `stdout` instances inside the loop and
    // writing to that handle could result in mangled output since
    // each write operation is handled by a different blocking thread.
    let mut stdout = io::stdout();

    for message in &messages {
        stdout.write_all(message.as_bytes()).await.unwrap();
        stdout.flush().await.unwrap();
    }
}

Implementations

impl AsFd for Stdout

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

impl AsRawFd for Stdout

fn as_raw_fd(self: &Self) -> RawFd

impl AsyncWrite for Stdout

fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Error>>
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<(), Error>>

impl Debug for Stdout

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

impl Freeze for Stdout

impl RefUnwindSafe for Stdout

impl Send for Stdout

impl Sync for Stdout

impl Unpin for Stdout

impl UnsafeUnpin for Stdout

impl UnwindSafe for Stdout

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>

impl<W> AsyncWriteExt for Stdout