Struct Stderr

pub struct Stderr { pub(in ::io::stdio) inner: &'static ReentrantLock<RefCell<StderrRaw>> }

A handle to the standard error stream of a process.

For more information, see the io::stderr 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.

Fields

inner: &'static ReentrantLock<RefCell<StderrRaw>>

Implementations

impl Stderr

fn lock(&self) -> StderrLock<'static>

Locks this handle to the standard error 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 foo() -> io::Result<()> {
    let stderr = io::stderr();
    let mut handle = stderr.lock();

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

    Ok(())
}

Trait Implementations

impl AsFd for Stderr

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

impl AsHandle for Stderr

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

impl AsRawFd for Stderr

fn as_raw_fd(&self) -> RawFd

impl AsRawHandle for Stderr

fn as_raw_handle(&self) -> RawHandle

impl Debug for Stderr

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

impl IsTerminal for Stderr

fn is_terminal(&self) -> bool

impl RefUnwindSafe for Stderr

impl StdioExt for Stderr

fn set_handle<T: Into<OwnedHandle>>(&mut self, handle: Option<T>) -> Result<()>
fn replace_handle<T: Into<OwnedHandle>>(&mut self, replace_with: T) -> Result<Option<BorrowedHandle<'static>>>
fn take_handle(&mut self) -> Result<Option<BorrowedHandle<'static>>>

impl StdioExt for Stderr

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

impl UnwindSafe for Stderr

impl Write for Stderr

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

Auto Trait Implementations

impl Freeze for Stderr

impl Send for Stderr

impl Sync for Stderr

impl Unpin for Stderr

impl UnsafeUnpin for Stderr

Blanket Implementations

impl<T> Any for Stderr where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Stderr where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Stderr where T: ?Sized,

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

impl<T> From<T> for Stderr

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for Stderr where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for Stderr

impl<T, U> Into<U> for Stderr 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 Stderr where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for Stderr where U: TryFrom<T>,

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