diff --git a/filedescriptor/src/lib.rs b/filedescriptor/src/lib.rs index 1fe09f1eb..50dcab9ab 100644 --- a/filedescriptor/src/lib.rs +++ b/filedescriptor/src/lib.rs @@ -109,6 +109,14 @@ impl FileDescriptor { pub fn try_clone(&self) -> Fallible { self.handle.try_clone().map(|handle| Self { handle }) } + + /// A convenience method for creating a `std::process::Stdio` object + /// to be used for eg: redirecting the stdio streams of a child + /// process. The `Stdio` is created using a duplicated handle so + /// that the source handle remains alive. + pub fn as_stdio(&self) -> Fallible { + self.as_stdio_impl() + } } pub struct Pipes { diff --git a/filedescriptor/src/unix.rs b/filedescriptor/src/unix.rs index ca1c6ba9a..00dd4f87d 100644 --- a/filedescriptor/src/unix.rs +++ b/filedescriptor/src/unix.rs @@ -161,7 +161,8 @@ impl FileDescriptor { } } - pub fn as_stdio(&self) -> Fallible { + #[inline] + pub(crate) fn as_stdio_impl(&self) -> Fallible { let duped = OwnedHandle::dup(self)?; let fd = duped.into_raw_fd(); let stdio = unsafe { std::process::Stdio::from_raw_fd(fd) }; diff --git a/filedescriptor/src/windows.rs b/filedescriptor/src/windows.rs index 3b6fd586b..be6d857fc 100644 --- a/filedescriptor/src/windows.rs +++ b/filedescriptor/src/windows.rs @@ -97,7 +97,8 @@ impl IntoRawHandle for OwnedHandle { } impl FileDescriptor { - pub fn as_stdio(&self) -> Fallible { + #[inline] + pub(crate) fn as_stdio_impl(&self) -> Fallible { let duped = self.handle.try_clone()?; let handle = duped.into_raw_handle(); let stdio = unsafe { std::process::Stdio::from_raw_handle(handle) };