elaborate 2.2.0

Wrappers for standard library functions and types to produce more elaborate error messages
Documentation
// This file was automatically generated by `elaborate`.
// https://github.com/trailofbits/elaborate

#[allow(unused_imports)]
use anyhow::Context;


#[cfg(feature = "stdio_swap")]
#[cfg(unix)]
pub trait StdioExtContext: std :: os :: unix :: io :: StdioExt {
/// Redirects the stdio file descriptor and returns a new `OwnedFd`
/// backed by the previous file description.
/// 
/// See [`set_fd()`] for details.
/// 
/// [`set_fd()`]: StdioExt::set_fd
fn replace_fd_wc < T : core :: convert :: Into < std :: os :: fd :: OwnedFd > > ( & mut self , replace_with : T ) -> crate :: rewrite_output_type ! ( std :: io :: Result < std :: os :: fd :: OwnedFd > ) {
    < Self as :: std :: os :: unix :: io :: StdioExt > :: replace_fd(self, replace_with)
        .with_context(|| crate::call_failed!(Some(self), "replace_fd", crate::CustomDebugMessage("value of type impl Into")))
}
/// 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_renumber` on wasip1
/// - `dup2` on most unixes
/// 
/// [currently]: crate::io#platform-specific-behavior
/// 
/// ```
/// #![feature(stdio_swap)]
/// use std::io::{self, Read, Write};
/// use std::os::unix::io::StdioExt;
/// 
/// fn main() -> io::Result<()> {
///    let (reader, mut writer) = io::pipe()?;
///    let mut stdin = io::stdin();
///    stdin.set_fd(reader)?;
///    writer.write_all(b"Hello, world!")?;
///    let mut buffer = vec![0; 13];
///    assert_eq!(stdin.read(&mut buffer)?, 13);
///    assert_eq!(&buffer, b"Hello, world!");
///    Ok(())
/// }
/// ```
fn set_fd_wc < T : core :: convert :: Into < std :: os :: fd :: OwnedFd > > ( & mut self , fd : T ) -> crate :: rewrite_output_type ! ( std :: io :: Result < ( ) > ) {
    < Self as :: std :: os :: unix :: io :: StdioExt > :: set_fd(self, fd)
        .with_context(|| crate::call_failed!(Some(self), "set_fd", crate::CustomDebugMessage("value of type impl Into")))
}
/// Redirects the stdio file descriptor to the null device (`/dev/null`)
/// and returns a new `OwnedFd` backed 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.
/// 
/// [`set_fd()`]: StdioExt::set_fd
fn take_fd_wc ( & mut self ) -> crate :: rewrite_output_type ! ( std :: io :: Result < std :: os :: fd :: OwnedFd > ) {
    < Self as :: std :: os :: unix :: io :: StdioExt > :: take_fd(self)
        .with_context(|| crate::call_failed!(Some(self), "take_fd"))
}
}

#[cfg(feature = "stdio_swap")]
#[cfg(unix)]
impl<T> StdioExtContext for T where T: std :: os :: unix :: io :: StdioExt {}