Trait StdioExt
trait StdioExt: crate::sealed::Sealed
Required Methods
fn set_fd<T: Into<OwnedFd>>(self: &mut Self, fd: T) -> io::Result<()>Redirects the stdio file descriptor to point to the file description underpinning
fd.Rust std::io write buffers (if any) are flushed, but other runtimes (e.g. C stdio) or libraries that acquire a clone of the file descriptor will not be aware of this change.
Platform-specific behavior
This is currently implemented using
fd_renumberon wasip1dup2on most unixes
use ; use StdioExt;fn replace_fd<T: Into<OwnedFd>>(self: &mut Self, replace_with: T) -> io::Result<OwnedFd>Redirects the stdio file descriptor and returns a new
OwnedFdbacked by the previous file description.See
set_fd()for details.fn take_fd(self: &mut Self) -> io::Result<OwnedFd>Redirects the stdio file descriptor to the null device (
/dev/null) and returns a newOwnedFdbacked by the previous file description.Programs that communicate structured data via stdio can use this early in
main()to extract the fds, treat them as other IO types (File,UnixStream, etc), apply custom buffering or avoid interference from stdio use later in the program.See
set_fd()for additional details.
Implementors
impl StdioExt for crate::io::Stderrimpl StdioExt for crate::io::StdinLock<'_>impl StdioExt for crate::io::StdoutLock<'_>impl StdioExt for crate::io::Stdinimpl StdioExt for crate::io::StderrLock<'_>impl StdioExt for crate::io::Stdout