feat: add ipipe

This commit is contained in:
2021-03-21 17:36:51 +08:00
parent e55f773860
commit dd05e11b30
3 changed files with 304 additions and 0 deletions

24
__linux/ipipe/src/main.rs Normal file
View File

@@ -0,0 +1,24 @@
use ipipe::Pipe;
use std::thread;
use std::io::{BufRead, BufReader, Write};
const CANCEL: u8 = 24;
fn main() {
let pipe = Pipe::create().unwrap();
println!("Name: {}", pipe.path().display());
let writer = pipe.clone();
thread::spawn(move || print_nums(writer));
for line in BufReader::new(pipe).lines() {
println!("{}", line.unwrap());
}
}
fn print_nums(mut pipe: Pipe) {
for i in 1..=10 {
// pipe.write_all(format!("{}\n", i).as_bytes());
writeln!(&mut pipe, "{}", i).unwrap();
}
write!(&mut pipe, "{}", CANCEL as char).unwrap();
}