filedescriptor: Add into_stdio conversion (#7789)
This commit is contained in:
1 parent
26270fd8d4
commit
21ad43049b
3 files changed
+24
No files matched your search
@@ -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.
|
||||
///
|
||||
|
||||
@@ -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)?;
|
||||
|
||||
@@ -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()?;
|
||||
|
||||
Reference in new issue
Block a user