#fifo #pipe #filter #thread

runnel

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

26 releases

0.4.0 Aug 19, 2025
0.3.19 Jun 19, 2024
0.3.17 Feb 12, 2023
0.3.11 Jun 13, 2022
0.3.4 Mar 8, 2021

#102 in Testing

Download history 83/week @ 2025-10-15 90/week @ 2025-10-22 52/week @ 2025-10-29 47/week @ 2025-11-05 52/week @ 2025-11-12 52/week @ 2025-11-19 59/week @ 2025-11-26 49/week @ 2025-12-03 40/week @ 2025-12-10 54/week @ 2025-12-17 62/week @ 2025-12-24 47/week @ 2025-12-31 14/week @ 2026-01-07 56/week @ 2026-01-14 50/week @ 2026-01-21 45/week @ 2026-01-28

172 downloads per month
Used in 12 crates

MIT/Apache

54KB
1.5K 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, in memory line pipe.

Features

  • support common operation: stdin, stdout, stderr, stringin, stringout, pipein, pipeout, linepipein and linepipeout.
  • thin interface
  • support testing io stream
  • minimum support rustc 1.60.0 (7737e0b5c 2022-04-04)

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 input stream
let mut lines_iter = sioe.pg_in().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 output stream
#[rustfmt::skip]
let res = sioe.pg_out().lock()
    .write_fmt(format_args!("{}\nACBDE\nefgh\n", 1234));
assert!(res.is_ok());
assert_eq!(sioe.pg_out().lock().buffer_to_string(), "1234\nACBDE\nefgh\n");

// pluggable error stream
#[rustfmt::skip]
let res = sioe.pg_err().lock()
    .write_fmt(format_args!("{}\nACBDE\nefgh\n", 1234));
assert!(res.is_ok());
assert_eq!(sioe.pg_err().lock().buffer_to_string(), "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")
    .pg_out(a_out)    // pluggable pipe out
    .build();
let handler = std::thread::spawn(move || {
    for line in sioe.pg_in().lines().map(|l| l.unwrap()) {
        let mut out = sioe.pg_out().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")
    .pg_in(a_in)      // pluggable pipe in
    .build();
let mut lines_iter = sioe.pg_in().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());

Example of linepipeio :

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

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

// a working thread
let sioe = RunnelIoeBuilder::new()
    .fill_stringio_with_str("ABCDE\nefgh\n")
    .pg_out(a_out)    // pluggable pipe out
    .build();
let handler = std::thread::spawn(move || {
    for line in sioe.pg_in().lines().map(|l| l.unwrap()) {
        let _ = sioe.pg_out().write_line(line);
        let _ = sioe.pg_out().flush_line();
    }
});

// a main thread
let sioe = RunnelIoeBuilder::new()
    .fill_stringio_with_str("ABCDE\nefgh\n")
    .pg_in(a_in)      // pluggable pipe in
    .build();
let mut lines_iter = sioe.pg_in().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