runnel

The pluggable io stream. now support: stdio, string io, in memory pipe.

Features

Examples

Example of stdio :

rust use runnel::RunnelIoeBuilder; let sioe = RunnelIoeBuilder::new().build();

Example of stringio :

```rust use runnel::RunnelIoeBuilder; use std::io::{BufRead, Write};

let sioe = RunnelIoeBuilder::new() .fillstringiowith_str("ABCDE\nefgh\n") .build();

// pluggable stream in let mut linesiter = sioe.pin().lock().lines().map(|l| l.unwrap()); asserteq!(linesiter.next(), Some(String::from("ABCDE"))); asserteq!(linesiter.next(), Some(String::from("efgh"))); asserteq!(lines_iter.next(), None);

// pluggable stream out

[rustfmt::skip]

let res = sioe.pout().lock() .writefmt(formatargs!("{}\nACBDE\nefgh\n", 1234)); assert!(res.isok()); asserteq!(sioe.pout().lock().buffer_str(), "1234\nACBDE\nefgh\n");

// pluggable stream err

[rustfmt::skip]

let res = sioe.perr().lock() .writefmt(formatargs!("{}\nACBDE\nefgh\n", 1234)); assert!(res.isok()); asserteq!(sioe.perr().lock().buffer_str(), "1234\nACBDE\nefgh\n"); ```

Example of pipeio :

```rust use runnel::RunnelIoeBuilder; use runnel::medium::pipeio::pipe; use std::io::{BufRead, Write};

// create in memory pipe let (aout, ain) = pipe(1);

// a working thread let sioe = RunnelIoeBuilder::new() .fillstringiowithstr("ABCDE\nefgh\n") .pout(aout) // pluggable pipe out .build(); let handler = std::thread::spawn(move || { for line in sioe.pin().lock().lines().map(|l| l.unwrap()) { let mut out = sioe.pout().lock(); let _ = out.writefmt(formatargs!("{}\n", line)); let _ = out.flush(); } });

// a main thread let sioe = RunnelIoeBuilder::new() .fillstringiowithstr("ABCDE\nefgh\n") .pin(ain) // pluggable pipe in .build(); let mut linesiter = sioe.pin().lock().lines().map(|l| l.unwrap()); asserteq!(linesiter.next(), Some(String::from("ABCDE"))); asserteq!(linesiter.next(), Some(String::from("efgh"))); asserteq!(lines_iter.next(), None);

assert!(handler.join().is_ok()); ```

Changelogs

This crate's changelog here.

License

This project is licensed under either of

at your option.