#io-stream #pipe #thread #filter #fifo #stdio #stdin

runnel

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

25 releases

0.3.19 Jun 19, 2024
0.3.17 Feb 12, 2023
0.3.11 Jun 13, 2022
0.3.9 Nov 14, 2021
0.3.4 Mar 8, 2021

#77 in Concurrency

Download history 125/week @ 2024-04-01 21/week @ 2024-04-08 35/week @ 2024-04-15 41/week @ 2024-04-22 43/week @ 2024-04-29 27/week @ 2024-05-06 38/week @ 2024-05-13 48/week @ 2024-05-20 62/week @ 2024-05-27 229/week @ 2024-06-03 68/week @ 2024-06-10 782/week @ 2024-06-17 44/week @ 2024-06-24 37/week @ 2024-07-01 26/week @ 2024-07-08 41/week @ 2024-07-15

162 downloads per month
Used in 12 crates

MIT/Apache

47KB
1K SLoC

runnel

crate Docs Rust Version Apache2/MIT licensed Test ubu Test mac Test win

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.57.0 (f1edd0429 2021-11-29)

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_with_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_with_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();
        let _ = out.write_fmt(format_args!("{}\n", line));
        let _ = out.flush();
    }
});

// a main thread
let sioe = RunnelIoeBuilder::new()
    .fill_stringio_with_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());

Changelogs

This crate's changelog here.

License

This project is licensed under either of

at your option.

No runtime deps