#pipe #fifo #filter #threads

runnel

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

12 releases

0.3.6 Apr 6, 2021
0.3.5 Apr 3, 2021
0.3.4 Mar 8, 2021
0.3.0 Feb 20, 2021
0.1.2 Jan 24, 2021

#68 in Testing

Download history 27/week @ 2021-02-22 46/week @ 2021-03-01 74/week @ 2021-03-08 7/week @ 2021-03-15 24/week @ 2021-03-22 49/week @ 2021-03-29 44/week @ 2021-04-05 32/week @ 2021-04-12 32/week @ 2021-04-19 4/week @ 2021-04-26 18/week @ 2021-05-03 3/week @ 2021-05-10 15/week @ 2021-05-17 5/week @ 2021-05-24 4/week @ 2021-05-31 19/week @ 2021-06-07

137 downloads per month
Used in less than 11 crates

MIT/Apache

44KB
1K SLoC

runnel

runnel is the pluggable io stream. now support: stdio, string io, in memory pipe.

Features

  • support common operation: stdin, stdout, stderr, stringin, stringout, pipein and pipeout.
  • thin interface
  • support testing stream io
  • minimum support rustc 1.38.0

Examples

Example of stdio :

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

Example of stringio :

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

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

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

// pluggable stream out
#[rustfmt::skip]
let res = sioe.pout().lock()
    .write_fmt(format_args!("{}\nACBDE\nefgh\n", 1234));
assert!(res.is_ok());
assert_eq!(sioe.pout().lock().buffer_str(), "1234\nACBDE\nefgh\n");

// pluggable stream err
#[rustfmt::skip]
let res = sioe.perr().lock()
    .write_fmt(format_args!("{}\nACBDE\nefgh\n", 1234));
assert!(res.is_ok());
assert_eq!(sioe.perr().lock().buffer_str(), "1234\nACBDE\nefgh\n");

Example of pipeio :

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

// create in memory pipe
let (a_out, a_in) = pipe(1);

// a working thread
let sioe = RunnelIoeBuilder::new()
    .fill_stringio_wit_str("ABCDE\nefgh\n")
    .pout(a_out)    // 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();
        out.write_fmt(format_args!("{}\n", line)).unwrap();
        out.flush().unwrap();
    }
});

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

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

No runtime deps

~96KB