Function std::io::stdout_locked
pub fn stdout_locked() -> StdoutLock<'static>ⓘNotable traits for StdoutLock<'_>impl Write for StdoutLock<'_>
Constructs a new locked handle to the standard output of the current process.
Each handle returned is a guard granting locked access to a shared global buffer whose access is synchronized via a mutex. If you need more explicit control over locking, for example, in a multi-threaded program, use the io::stdout
function to obtain an unlocked handle, along with the Stdout::lock
method.
The lock is released when the returned guard goes out of scope. The returned guard also implements the Write
trait for writing data.
Note: Windows Portability Consideration
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.
Examples
#![feature(stdio_locked)] use std::io::{self, Write}; fn main() -> io::Result<()> { let mut handle = io::stdout_locked(); handle.write_all(b"hello world")?; Ok(()) }
© 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/fn.stdout_locked.html