Function pipefile::pipe [] [src]

pub fn pipe() -> Result<PipeFile>

Make a new pipe.


use std::io::{Write, BufReader, BufRead};
let p = pipefile::pipe().expect("couldn't create pipe");
// Start the write.
let mut writer = p.write_end;
let write_thread = std::thread::spawn(move || {
    writer.write("hello world".as_bytes())
          .expect("couldn't write message");
// Do the read.
let mut reader = BufReader::new(&p.read_end);
let mut message = String::new();
reader.read_line(&mut message)
      .expect("couldn't read message");
// Clean up and check.
      .expect("couldn't finish writer");
assert_eq!(message, "hello world");