about summary refs log tree commit diff
path: root/src/libstd/sys/unix/process/process_common.rs
diff options
context:
space:
mode:
authorJosh Stone <jistone@redhat.com>2017-06-06 15:42:55 -0700
committerJosh Stone <jistone@redhat.com>2017-06-06 15:42:55 -0700
commit9debe91675222782e08fbb15bb6359a05bf85131 (patch)
tree3bc0a130617f2cc0675f47b1647da77e00738412 /src/libstd/sys/unix/process/process_common.rs
parenta032cb89c5d9b436c1c57f8a6d5961d898f5c2b6 (diff)
downloadrust-9debe91675222782e08fbb15bb6359a05bf85131.tar.gz
rust-9debe91675222782e08fbb15bb6359a05bf85131.zip
Add conversions from File and Child* handles to Stdio
`Stdio` now implements `From<ChildStdin>`, `From<ChildStdout>`,
`From<ChildStderr>`, and `From<File>`.

The `Command::stdin`/`stdout`/`stderr` methods now take any type that
implements `Into<Stdio>`.

This makes it much easier to write shell-like command chains, piping to
one another and redirecting to and from files.  Otherwise one would need
to use the unsafe and OS-specific `from_raw_fd` or `from_raw_handle`.
Diffstat (limited to 'src/libstd/sys/unix/process/process_common.rs')
-rw-r--r--src/libstd/sys/unix/process/process_common.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libstd/sys/unix/process/process_common.rs b/src/libstd/sys/unix/process/process_common.rs
index e9f41009064..32fcee1e461 100644
--- a/src/libstd/sys/unix/process/process_common.rs
+++ b/src/libstd/sys/unix/process/process_common.rs
@@ -315,6 +315,18 @@ impl Stdio {
     }
 }
 
+impl From<AnonPipe> for Stdio {
+    fn from(pipe: AnonPipe) -> Stdio {
+        Stdio::Fd(pipe.into_fd())
+    }
+}
+
+impl From<File> for Stdio {
+    fn from(file: File) -> Stdio {
+        Stdio::Fd(file.into_fd())
+    }
+}
+
 impl ChildStdio {
     pub fn fd(&self) -> Option<c_int> {
         match *self {