os_pipe 0.2.0

an adaptation of the OS pipe code from stdlib as a standalone library
Documentation

os_pipe.rs Build Status Build status

A cross-platform Rust library for opening anonymous pipes, backed by nix on Unix and winapi on Windows. If anyone needs it, we could also add support for named pipes and IOCP (using random names) on Windows, or creating filesystem FIFO's on Unix.

Current API:

  • pipe() returns two std::fs::File objects, the reading and writing ends of the new pipe, as the read and write members of a Pair struct.
  • parent_stdin(), parent_stdout(), and parent_stderr() return duplicated copies of the stdin/stdout/stderr file handles as std::process::Stdio objects that can be passed to child processes. This is useful for e.g. swapping stdout and stderr.
  • stdio_from_file() is a helper function to safely convert a std::fs::File to a std::process::Stdio object, for passing to child processes. The standard library supports this conversion, but it requires platform-specific traits and takes an unsafe call. Currently there's not really such a thing as a "closed file" in Rust, since closing requires dropping, but if Rust ever introduces closed files in the future this function will panic on them.