Add `into_inner`-api to associate to other process
This commit is contained in:
parent
f6782f6f0c
commit
d8ee0d6853
90
src/lib.rs
90
src/lib.rs
|
@ -443,6 +443,36 @@ pub struct ChildStdin(
|
|||
#[cfg(unix)] Async<std::process::ChildStdin>,
|
||||
);
|
||||
|
||||
impl ChildStdin {
|
||||
/// Unwraps the inner I/O handle.
|
||||
///
|
||||
/// This method will **not** put the I/O handle back into blocking mode.
|
||||
/// You can use it to associate to the next process.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// # futures_lite::future::block_on(async {
|
||||
/// use async_process::Command;
|
||||
///
|
||||
/// let mut ls_child = Command::new("ls").spawn()?;
|
||||
/// let stdio : std::process::Stdio = ls_child.stdout.take().unwrap().into_inner().await?.into();
|
||||
///
|
||||
/// let mut echo_child = Command::new("echo").stdout(stdio).spawn()?;
|
||||
///
|
||||
/// # std::io::Result::Ok(()) });
|
||||
/// ```
|
||||
pub async fn into_inner(self) -> io::Result<std::process::ChildStdin> {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(windows)] {
|
||||
self.0.into_inner().await
|
||||
} else if #[cfg(unix)] {
|
||||
self.0.into_inner()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl io::AsyncWrite for ChildStdin {
|
||||
fn poll_write(
|
||||
mut self: Pin<&mut Self>,
|
||||
|
@ -470,6 +500,36 @@ pub struct ChildStdout(
|
|||
#[cfg(unix)] Async<std::process::ChildStdout>,
|
||||
);
|
||||
|
||||
impl ChildStdout {
|
||||
/// Unwraps the inner I/O handle.
|
||||
///
|
||||
/// This method will **not** put the I/O handle back into blocking mode.
|
||||
/// You can use it to associate to the next process.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// # futures_lite::future::block_on(async {
|
||||
/// use async_process::Command;
|
||||
///
|
||||
/// let mut ls_child = Command::new("ls").spawn()?;
|
||||
/// let stdio : std::process::Stdio = ls_child.stdout.take().unwrap().into_inner().await?.into();
|
||||
///
|
||||
/// let mut echo_child = Command::new("echo").stdout(stdio).spawn()?;
|
||||
///
|
||||
/// # std::io::Result::Ok(()) });
|
||||
/// ```
|
||||
pub async fn into_inner(self) -> io::Result<std::process::ChildStdout> {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(windows)] {
|
||||
self.0.into_inner().await
|
||||
} else if #[cfg(unix)] {
|
||||
self.0.into_inner()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl io::AsyncRead for ChildStdout {
|
||||
fn poll_read(
|
||||
mut self: Pin<&mut Self>,
|
||||
|
@ -489,6 +549,36 @@ pub struct ChildStderr(
|
|||
#[cfg(unix)] Async<std::process::ChildStderr>,
|
||||
);
|
||||
|
||||
impl ChildStderr {
|
||||
/// Unwraps the inner I/O handle.
|
||||
///
|
||||
/// This method will **not** put the I/O handle back into blocking mode.
|
||||
/// You can use it to associate to the next process.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```no_run
|
||||
/// # futures_lite::future::block_on(async {
|
||||
/// use async_process::Command;
|
||||
///
|
||||
/// let mut ls_child = Command::new("ls").spawn()?;
|
||||
/// let stdio : std::process::Stdio = ls_child.stdout.take().unwrap().into_inner().await?.into();
|
||||
///
|
||||
/// let mut echo_child = Command::new("echo").stdout(stdio).spawn()?;
|
||||
///
|
||||
/// # std::io::Result::Ok(()) });
|
||||
/// ```
|
||||
pub async fn into_inner(self) -> io::Result<std::process::ChildStderr> {
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(windows)] {
|
||||
self.0.into_inner().await
|
||||
} else if #[cfg(unix)] {
|
||||
self.0.into_inner()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl io::AsyncRead for ChildStderr {
|
||||
fn poll_read(
|
||||
mut self: Pin<&mut Self>,
|
||||
|
|
Loading…
Reference in New Issue