chiark / gitweb /
childio: Some type aliases
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 31 May 2021 13:08:33 +0000 (14:08 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 31 May 2021 13:46:05 +0000 (14:46 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/childio.rs

index 35b43bb42f1a5f6acbbcf7e60bc9a4ad2f783bdb..02bd7dcd2e75602a8a1614a77db81d7908095d82 100644 (file)
@@ -4,7 +4,7 @@
 
 use crate::prelude::*;
 
-use std::process::{self, ChildStdin, ChildStdout};
+use std::process;
 
 #[derive(Debug)]
 pub struct ChildIo<RW> {
@@ -12,6 +12,10 @@ pub struct ChildIo<RW> {
   child: Arc<Mutex<ChildWrapper>>,
 }
 
+pub type Stdin  = ChildIo<process::ChildStdin >;
+pub type Stdout = ChildIo<process::ChildStdout>;
+pub type Pair   = (Stdin /*w*/, Stdout /*r*/);
+
 #[derive(Debug)]
 struct ChildWrapper {
   reported: bool,
@@ -43,8 +47,7 @@ impl<RW> ChildIo<RW> {
   }
 }
 
-pub fn new_pair(mut input: process::Child, desc: String)
-                -> (ChildIo<ChildStdin>, ChildIo<ChildStdout>) {
+pub fn new_pair(mut input: process::Child, desc: String) -> Pair {
   let stdin  = input.stdin .take().expect("ChildIo::pair, no stdin¬");
   let stdout = input.stdout.take().expect("ChildIo::pair, no stdout¬");
   let wrapper = Arc::new(Mutex::new(ChildWrapper {
@@ -57,8 +60,7 @@ pub fn new_pair(mut input: process::Child, desc: String)
 }
 
 #[throws(io::Error)]
-pub fn run_pair(mut cmd: process::Command, desc: String)
-                -> (ChildIo<ChildStdin>, ChildIo<ChildStdout>) {
+pub fn run_pair(mut cmd: process::Command, desc: String) -> Pair {
   cmd.stdin (Stdio::piped());
   cmd.stdout(Stdio::piped());
   new_pair(cmd.spawn()?, desc)