filedescriptor: Add into_stdio conversion (#7789)

This commit is contained in:
xtqqczze authored and GitHub committed 2026-08-05 10:12:36 +02:00
1 parent 26270fd8d4
commit 21ad43049b
3 files changed
+24

No files matched your search

+12
View File
@@ -304,6 +304,12 @@ impl FileDescriptor {
self.as_stdio_impl()
}
/// A convenience method for creating a `std::process::Stdio` object,
/// transferring ownership of the underlying handle to the returned `Stdio`.
pub fn into_stdio(self) -> std::process::Stdio {
self.into_stdio_impl()
}
/// A convenience method for creating a `std::fs::File` object.
/// The `File` is created using a duplicated handle so
/// that the source handle remains alive.
@@ -331,6 +337,12 @@ impl FileDescriptor {
}
}
impl From<FileDescriptor> for std::process::Stdio {
fn from(value: FileDescriptor) -> Self {
value.into_stdio()
}
}
/// Represents the readable and writable ends of a pair of descriptors
/// connected via a kernel pipe.
///
+6
View File
@@ -265,6 +265,12 @@ impl FileDescriptor {
Ok(stdio)
}
#[inline]
pub(crate) fn into_stdio_impl(self) -> std::process::Stdio {
let fd = self.into_raw_fd();
unsafe { std::process::Stdio::from_raw_fd(fd) }
}
#[inline]
pub(crate) fn as_file_impl(&self) -> Result<std::fs::File> {
let duped = OwnedHandle::dup(self)?;
+6
View File
@@ -233,6 +233,12 @@ impl FileDescriptor {
Ok(stdio)
}
#[inline]
pub(crate) fn into_stdio_impl(self) -> std::process::Stdio {
let handle = self.into_raw_handle();
unsafe { std::process::Stdio::from_raw_handle(handle) }
}
#[inline]
pub(crate) fn as_file_impl(&self) -> Result<std::fs::File> {
let duped = self.handle.try_clone()?;