Crates.io | runnel |
lib.rs | runnel |
version | 0.4.0 |
created_at | 2021-01-24 12:25:55.583294+00 |
updated_at | 2025-08-19 14:19:15.370156+00 |
description | the pluggable io stream. now support: stdio, string io, in memory pipe, line pipe |
homepage | |
repository | https://github.com/aki-akaguma/runnel |
max_upload_size | |
id | 346001 |
size | 118,204 |
The pluggable io stream. now support: stdio, string io, in memory pipe, in memory line pipe.
use runnel::RunnelIoeBuilder;
let sioe = RunnelIoeBuilder::new().build();
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");
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());
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());
This project is licensed under either of
at your option.