os_pipe.rs
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 twostd::fs::File
objects, the reading and writing ends of the new pipe, as theread
andwrite
members of aPair
struct.parent_stdin()
,parent_stdout()
, andparent_stderr()
return duplicated copies of the stdin/stdout/stderr file handles asstd::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 astd::fs::File
to astd::process::Stdio
object, for passing to child processes. The standard library supports this conversion, but it requires platform-specific traits and takes anunsafe
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.